Count Files across multiple directories

May 19, 2009 at 12:38:37
Specs: Windows
I'm trying to come up with a bat file to count the amount of files of a certain name and output it to a certain file. I can do that through:

dir /a /s d:\dir\ex20090518.log | find "" /c /v >count.txt

However, I want to do this through multiple directories at once. So basically, I want this:

dir /a /s d:\dir\*\*\*\ex20090518.log | find "" /c /v >count.txt

Any thoughts on how to do this?


See More: Count Files across multiple directories

Report •

May 19, 2009 at 17:50:17
/s option of dir enables you to recurse directories already...

Report •

May 20, 2009 at 06:44:36
Then I don't get why it is not working. I know those files exist in those locations. So any thoughts why it doesn't work? I'm getting a "The filename, directory name, or volumen label syntax is incorrect" error. Not sure how that could be when I know the file with that name exists, the directory structure is there and the volume label is fine.

Any other thoughts?

Report •

May 20, 2009 at 06:53:32
I've gone back and done a static test where I filled in the *'s with actual directory names and it works fine. But the moment I put in an asterisk, it fails.

Report •

Related Solutions

May 20, 2009 at 09:20:14
Don't use an asterisk, just name the top-level directory where you want it to start searching downwards.

Report •

May 20, 2009 at 09:56:33
So then how would that work? Like this?

dir /a /s d:\dir\ | find "" /c /v >count.txt

And how would I specify a particular file name? Basically I would be looking for fileA.log and not fileB.log or any others.

Thanks for all of the help!

Report •

May 20, 2009 at 10:01:18
Well, I found it!!!

dir /a /s d:\dir |find "fileA.log" /c > count.txt

Works perfectly!!! Thank you all so much for your help!!!!!

Report •

Ask Question