Recently, I needed to count the number of files in a directory on a Windows server. Here’s the command that can easily be scripted. It can also be used on Windows client machines running Windows 10, etc.

dir/b/a-d c:\directory | find /v /c "::"

You can also specify a file share instead of a directory name:

Table of Contents
    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 "::"

    There are a few extra tips that are worth knowing when using this command. Firstly, it will count every file, even if the file is hidden by you or the operating system. If the count is showing higher than what you see in the directory, you may have to show all hidden files in Windows.

    Counting the Number of Files in a Directory, Command Line Style image 1

    Secondly, if you have a path that has a space in it, you need to use quotes around the path. For example:

    dir/b/a-d "c:\my directory" | find /v /c "::"

    Leave a Reply

    Your email address will not be published. Required fields are marked *