I needed to count the number of files in a directory on a Windows 2003 server. Here’s the command that can easily be scripted:
dir/b/a-d c:\directory | find /v /c “::”
You can also specify a file share instead of a directory name:
dir/b/a-d \\server\share | find /v /c “::”
If you want to count the number of files in a directory and all subdirectories, the command is:
dir/s/b/a-d \c:\directory | find /v /c “::”