Counting Files and Subfolders Using the Command Prompt

by Eric Wyatt
(last updated January 7, 2021)


In another article, we discussed how as we add more and more data to our computers. Over time, it is easy to lose track of how many items are stored in one folder. In that article, we discussed how to use PowerShell to quickly find the number of files and how to recursively search and see how many items are in any subfolders. While PowerShell is the more powerful command-line shell, some prefer using the regular old command line. Just as we did with PowerShell in the other article, we can use the power of command line to return the number of files and/or folders in a specific location. Follow these steps:

  1. Press theÊWindowsÊKey and type (without quotes) "CMD", and pressÊEnter. Windows opens a Command Prompt window.
  2. To search for the number of files within a directory, enter the following command. (Don't worry; I'll explain the command line in a moment.)
  3. dir "FilePath" /a:-d /s /b | find ":" /cÊ
  4. Press Enter. Command prompt will then return the number of files found within the directory you entered.

To find the number of subfolders within a directory enter the following command either in place of step 2 above or after step 3 and press Enter. (Again, I'll explain this command in a moment.)

dir "FilePath" /a :d /s /b | find ":" /cÊ

If you look at the two commands, they appear very similar. Let us look at what is happening here:

The dir command looks at the directory you specify in the "FilePath" location on your system. This ("FilePath") is the path to the directory or folder for which you want a count. Remember that the FilePath location needs to be contained within quote marks. A handy tip when it comes to entering your file path is once you type dir, followed by a space, click and drag the folder you are wanting information about into the Command Prompt window. Windows automatically places the file path with the accompanying quotes for you.

Next come the switches that control how the dir command does its work. The /a is used to specify which file attributes we want it to look at. In our instances we use either a ":d" or a ":-d". The ":d" tells dir to look only at directories (or subfolders) within the FilePath location. The use of ":-d", adding the dash in front of the "d", tells dir to pay attention to everything except the subfolders.

The /s switch makes the dir command recursive, meaning it will look inside each directory or subfolder within the "FilePath" location, not just the main folder. Finally, the /b switch reduces the amount of information returned by the dir command.

Next on the command line is a vertical bar (|), which is referred to as a "pipe." The pipe causes the output of the command that is just before it (dir) to be used as input for the command that immediately follows it (find). Thus, the ouput of the dir command will be used as input for the find command.

Which brings us to the find command. This command is used to find instances of one string within another. In this case, we are specifying that what follows the find command (":") should be found in the output produced by the dir command. Finally, the /c switch indicates that we want the find command to only return a count of how many lines of the dir output contain colons.

Knowing how to use the command prompt in this way can help you to quickly get the counts relating to the number of files or folders within a directory quickly and effortlessly.

 This tip (13819) applies to Windows 10.

Author Bio

Eric Wyatt

Eric Wyatt is a swell guy (or so his friends tell him). He is a formally trained designer and branding expert, bringing a wide range of skills to his Tips.Net articles. ...


Getting Started with Continue on PC

In todays on-the-go lifestyle, we tend to have multiple electronic devices. Easily being able to connect our devices can ...

Discover More

Changing Your DNS Server

Your DNS server is usually set by your Internet provider. You can change the default DNS to another server easily in ...

Discover More

Installing a Native Progressive Web App

Windows 10 with the Edge Chromium browser allows you to install Progressive Web Apps. These allow for fast installation ...

Discover More
More WindowsTips

Changing Font Size in a Command Prompt Window

If you work at the command level very much, you may want to change the fonts that are used. You can control what ...

Discover More

Moving Files Using the Command Line

The MOVE command can be a timesaver over trying to do the similar sort of thing with File Explorer. You can move hundreds ...

Discover More

Understanding the Command Line For Loop

A niche command that sometimes comes in handy is the FOR loop. It has several forms and therefore can serve several ...

Discover More

FREE SERVICE: Get tips like this every week in WindowsTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.


If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is five minus 4?

2021-01-04 20:48:16


Looks like several end marks that should be quotes in the cmd line descriptions on my computer turned into Ê character. Did not check it in any other browser. This was noticed in the EDGE browser,

2021-01-04 15:10:30

Glenn Case

While I can drag/drop a directory into the command prompt window, on my system it does not place the directory name inside quotes.

Another thing which might be noted is that if you want the current directory to be searched, replace the "FilePath" with a single period.

2021-01-04 06:27:00


What is the character "Ê" at the end of the command?
Commands worked well without it but gave "Invalid switch" with it.

Newest Tips

FREE SERVICE: Get tips like this every week in WindowsTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.