By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

FUNCTION to count NUMBER of files matching a pattern and specific length/not length

I realize this can be done with a custom routine. I'm wondering if there is a single function to do this (or command that sets a variable):

We download multiple date-named files with the name format XYZ_DEN_yyyymmdd.txt, e.g., XYZ_DEN_20191222.txt. There is one file per day, so on Mondays that would normally be 3 files.

Those files usually are empty, i.e., zero-length, but sometimes not. Today there is one length 385 and two length 0.

We also get files (with a different name pattern) that sometimes only contain a header, one header is length 566 and the other is length 662.

I'm wondering if there is a function that basically returns the following:

1) In a folder or set of subfolders
2) Look for all filenames matching a specific pattern
3a) Return the number of matching files that are a specific length
3b) the number of matching files that are not that specific length.
After you run the DIR command, the environment variable "_dir_files" will contain the number of files found. So if you can come up with a DIR command with ranges and file specifications that will (or would) display the files you are interested in, then that variable can be used to get the count. The size range specification can be used to select or exclude files of specific size ranges. If you really need this to be a function, you probably could define a custom function.
Indeed. The function @FILES probably uses the same code. The one difference I've discovered is that DIR can be used with multiple file specs (DIR a*.txt b*.docx). Each matching set is displayed separately, but the variable _dir_files contains the total count. The @FILES function does not accept multiple file specs.

It looks like this will work:

- Nov 2019\*\zcs_20??-??-??*.txt" /[s566,566]]

Note that this was run from the \TXE folder even though it's looking in a different folder.

"Count all files of length 566 (header only) in any subfolder of \THR\In Q_A\2019\{month}\{day subfolders}\
that matches the pattern "zcs_{date} (no records).txt"

Similar threads