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

Oct 18, 2009
362
17
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
-or-
3b) the number of matching files that are not that specific length.
 
Jun 2, 2008
376
2
Newton, MA
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.
 
Jun 2, 2008
376
2
Newton, MA
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.
 
Oct 18, 2009
362
17
THANKS!

It looks like this will work:

[F:\CLIENT DOWNLOADS\TXE]echo %@files["F:\CLIENT DOWNLOADS\THR\In Q_A\2019\z 11
- Nov 2019\*\zcs_20??-??-??*.txt" /[s566,566]]
30

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
Thread starter Title Forum Replies Date
vefatica Documentation Function parameters Support 0
Jay Sage Documentation Function @DRIVE Missing in Help Lists Support 0
Joe Caverly How to? Get name of current LIBRARY function? Support 4
x13 WeekNum function? Support 3
Joe Caverly No blank line in TEXT...ENDTEXT in a LIBRARY function Support 8
cgunhouse Ctrl-C from within a library function Support 6
C email[string] function Support 10
Dick Johnson Using the @instr function Support 5
vefatica '}' in a library function? Support 3
D Can the argument to RETURN be a function expansion? Support 3
J Trouble with @full[] function. Support 3
Fross Quick Function Question Support 17
vefatica Quoting @Function parameters? Support 0
Joe Caverly Debugging a LIBRARY function Support 10
Steve Pitts Documentation @CAPI function summary Support 0
x13 %x$ in function Support 3
thorntonpg @eval function, interesting results any explanation? Support 3
x13 Function to get interface user-defined name? Support 10
vefatica Fixed Help @FUNCTION, missing paragraph Support 8
Mordachai Variable followed by function constantly failing... Support 5
nickles Call a complex function Support 13
M Fixed Cannot use the "Browse..." function in "Find files/text" dialogbox Support 2
R Function #IDOW returns only 2 characters Support 10
T scrput `` in alias or function Support 2
S International characters - TYPE vs %@LINE function Support 5
JohnQSmith WAD @REPEAT function Support 15
vefatica WAD Nested variable expansion in PDIR's @function[*]? Support 13
R In addition to ALIAS /Z and FUNCTION /Z, HISTORY /Z? Support 1
A pdir function usage Support 3
nikbackm FUNCTION with variable number of arguments Support 17
S %@REGQUERY function Support 1
Dan Glynhampton Documentation v15 help: Error on @TRIMALL function page Support 0
M Why doesn't this @Field function work? Support 0
fpefpe How to? user function Support 1
M Why is this function getting these results in these circumstances? Support 6
A WAD function return values with parentheses prevent evaluation of additional functions Support 31
M Just an out-of-curiosity question the List command vs. the @Lines function... Support 13
M How to? Just verification for what I think I know regarding "Function"... Support 4
Frank How to? need help with "function" Support 10
Joe Caverly How to? Function Key With INPUT Support 5
M How to? "Function" and "%[xxx]" Support 7
M Kind of a out-of-curiosity question re. the "Function" command... Support 5
M Simple question about "Function" command... Support 4
M Just a curiosity question related to the "Function" command... Support 2
C not sure of windows registry function use Support 2
Phileosophos The @urlencode function doesn't seem to URL encode Support 16
J issue to have "if" inside function Support 3
Frank is the search-function in VIEW working? Support 2
M Weird @Index function result... Support 7
M . and .. directories counted by @files function Support 5

Similar threads