In Windows, you can use the command prompt (cmd.exe) to count how many files of a specific file type are in a directory. You can also include files in sub-directories in this count.
Count Files in CMD Prompt
- Open cmd prompt (click Start -> type “cmd”)
- Run this command:
dir /s /b "c:\<path to your files>"\*.<file type> | find /c ".<file type>"
Example Count Command
dir /s /b "c:\inetpub\wwwroot"\*.php | find /c ".php"
DIR Command Switches
/s = include sub-directories
/b = uses bare format (no headers) in the “dir” command’s output
FIND Command Switches
/c = counts the number of times the search term appears
Using the ” | ” (pipe) operator, you are running the “dir” command to generate a list of files, then you are “piping” (or sending) that command’s output INTO another command as the input. In this case, we’re making that list of files be the input of the “find” command.
Make sure you substitute <path to your files> for the path in your file system. Also, you can use this to look for files of any file type, not just .php.
I hope this helped save you some time. Send me a message or leave a comment below if you have any questions!