How to count files in a folder with PowerShell, CMD, or File Explorer

How to count files in a folder with PowerShell, CMD, or File Explorer

Sometimes, you need to know exactly how many files or folders are stored inside a certain folder. Whether for work or your own statistics, if you have a Windows device, there are quite a few ways to find this information. So, if you’ve ever wondered how to count the number of files in a directory, read on. Here are four methods to count the items in a folder on Windows 11 or Windows 10, using File Explorer, PowerShell, and the Command Prompt:

Advertisement

NOTE: In this guide, I’m using Windows 11 to illustrate the methods for counting files, folders, and subfolders inside a directory. However, the methods work exactly the same in Windows 10 too.

1. How to use File Explorer to get the number of files in a folder

Do you want to count all the folders and files stored inside a certain folder and all its subfolders? An easy method to find this information is to use the Properties window of the selected folder. Open File Explorer, browse to your folder, and right-click (or press and hold) on the folder’s icon. On the contextual menu, select Properties. Alternatively, select the folder and press the Alt + Enter keys on your keyboard.

Opening the Properties of a folder

Opening the Properties of a folder

When the Properties window opens, Windows automatically starts counting the files and folders inside the selected directory. You can see the number of files and folders displayed in the Contains field.

The Properties window of a folder counts the files and subfolders

The Properties window of a folder counts the files and subfolders

Next, let’s see how to use PowerShell to get the number of files in a folder:

Advertisement

2. How to use PowerShell to count the files in a folder

PowerShell offers one of the best ways to count the files and subfolders stored inside a folder. Open PowerShell and head to the location of the folder. To do that, run the command:

cd path

…where path is your folder’s path.

For example, I want to count the files and subfolders found in my Documents folder, located in "F:\OneDrive," so I need to run this command:

cd "F:\OneDrive\Documents"

Using Powershell to get to a folder

Using Powershell to get to a folder

If you want to count the files and folders inside that directory, run this command:

(Get-ChildItem | Measure-Object).Count

Note that it does not work recursively; it only counts the first-level elements.

Using PowerShell to count the files and folders in a folder

Using PowerShell to count the files and folders in a folder

If you want to count only the folders inside your parent folder, run this command:

(Get-ChildItem -Directory | Measure-Object).Count

Using PowerShell to count the subfolders of a folder

Using PowerShell to count the subfolders of a folder

If you want to count only the files in the folder, run this command:

(Get-ChildItem -File | Measure-Object).Count

Using PowerShell to count the files in a folder

Using PowerShell to count the files in a folder

If you want to recursively count folders and/or files in your parent folder, add the Recurse parameter to any of the previous commands:

  • To recursively count all files and subfolders in a folder with PowerShell, run:
    (Get-ChildItem -Recurse | Measure-Object).Count
  • If you want to recursively count only the subfolders in a directory, run this command:
    (Get-ChildItem -Recurse -Directory | Measure-Object).Count
  • And to recursively count only the files inside a folder, use this command:
    (Get-ChildItem -Recurse -File | Measure-Object).Count

Using PowerShell to count all the files and folders in a folder, recursively

Using PowerShell to count all the files and folders in a folder, recursively

NOTE: Recursive counting means that you’re counting all the files and subfolders contained by a folder, not just the files and folders on the first level of the folder tree.

Advertisement

3. How to use CMD to count the files in a folder

If you need to list the number of files in a directory, you can also use Command Prompt. Open Command Prompt and run the following command:

dir /a:-d /s /b "Folder Path" | find /c ":\"

For example, to use CMD to count the files and subfolders in my "F:\OneDrive\Documents" folder, I need to run:

dir /a:-d /s /b "F:\OneDrive\Documents" | find /c ":\"

Using Command Prompt (CMD) to count the files in a folder

Using Command Prompt (CMD) to count the files in a folder

If you want to count the subfolders in a folder, run this command:

dir /a:d /s /b "Folder Path" | find /c ":\"

In my example, that would be:

dir /a:d /s /b "F:\OneDrive\Documents" | find /c ":\"

Using Command Prompt (CMD) to count the subfolders of a folder

Using Command Prompt (CMD) to count the subfolders of a folder

NOTE: Instead of using the previous commands to count the items in a folder with CMD, you could also run the dir command just like that, without any parameters. However, that will output the entire list of items in Command Prompt, and the number of items only appears at the end. It works, but it’s too verbose and doesn’t give you the clean results you get when using the parameters presented earlier in this section.

Advertisement

4. An alternative way to count the files in a folder with File Explorer

Just like the first method in this guide, this one also involves File Explorer. However, I left it until the end because it doesn’t work recursively. It counts only the files and folders on the first level of the folder tree, even if these folders contain other files and folders inside. Even so, it might be useful in certain situations.

Open File Explorer (Win + E) and head to the folder where the items you want to count are stored. The total number of items (both files and folders) stored inside is displayed in the lower-left corner of File Explorer’s user interface.

Using File Explorer to count the files and subfolders in a folder

Using File Explorer to count the files and subfolders in a folder

If you want to count only some of the files or folders stored inside your folder, select them and look at the bottom left side of the File Explorer interface. It should display the number of selected items.

Using File Explorer to count the selected items in a folder

Using File Explorer to count the selected items in a folder

That’s it!

Do you know other ways to count the files in a folder and its subfolders?

If you want to know exactly how many files and folders are inside a folder from your Windows computer, you now have several ways to find that out. Since there are more than a couple of methods to get this information, you can choose whichever fits best. If you have questions or if you know of other ways to count the items in a folder, don’t hesitate to leave a comment below.

Discover: Productivity Command Prompt Explorer PowerShell Programs Recommended Tutorials Windows