top of page

Get Counts of Files in Multiple Subdirectories


Today at work I used a batch file with the XCOPY command to copy a large number of files into a few hundred different subdirectories. I wanted to confirm that each subfolder had a certain number of files copied into it, but I didn't want to take the trouble of parsing through the results of a standard dir command (such as "dir /b /s /a-d >list.txt") which would generate a complete list of file paths for all files in a directory.

I was able to devise a command which gave me the path of each subdirectory followed by the number of files in it. See this command:

dir /a /s | findstr "Directory File(s)"

Adding a pipe | after the dir command followed by the findstr command filters the results for the strings listed in the parentheses. We get just the parts of the results we want to focus on.


bottom of page