Microsoft > Microsoft DOS

Batch file Count within folders of specific name

(1/1)

mrchip:
Hi All,

Can anyone help me on a Batch file code that would count a specific filename ?

I already know how to count number of files within a folder but i dont know how to incorporate it on a specific filename.

@echo off
for /f %%A in ('dir ^| find "File(s)"') do set cnt=%%A

Sample Filename EGRHI-Tenant1-01061219.csv = 061219 is the date of the sales file (not the date of the day)

something like count all files ?????-??????-??06??19.csv

I need to count all files on a monthly basis for example how many files on 0619.

If theres a blank that would ask me what month and year the better.

Many thanks

mrchip:
Anyone ?

Sidewinder:
There is no error checking for two digit responses to the prompts, but Ill leave that to you.


--- Code: ---@echo off
set /p mm=Enter Month:
set /p yy=Enter Year:
for /f %%A in ('dir *%mm%??%yy%.csv ^| find "File(s)"') do set cnt=%%A
echo %cnt%

--- End code ---

You can remove the last line. It was used it for testing.

Happy Coding  8)

Navigation

[0] Message Index

Go to full version