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

There are times when 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 for counting the elements found inside a folder, in Windows 10, using File Explorer, PowerShell, and the Command Prompt:

NOTE: To illustrate the methods for counting files, folders, and subfolders inside a directory, we're using Windows 10. However, the methods should also work in older versions of Windows, such as Windows 8.1 and Windows 7.

1. How to count the files in a folder, using File Explorer

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

When the Properties window opens, Windows 10 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

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

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, we want to count the files and subfolders found in our Documents folder, located in "E:\OneDrive," so we need to run cd "E:\OneDrive\Documents".

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

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

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

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

  • Recursively count all files and subfolders in a folder: (Get-ChildItem -Recurse | Measure-Object).Count
  • Recursively count only subfolders in a directory: (Get-ChildItem -Recurse -Directory | Measure-Object).Count
  • Recursively count only files in a folder: (Get-ChildItem -Recurse -File | Measure-Object).Count
Using PowerShell to count all the files and folders in a folder, recursively

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

3. How to count the files in a folder, using Command Prompt (cmd)

You can also use the Command Prompt. To count the folders and files in a folder, open the Command Prompt and run the following command: dir /a:-d /s /b "Folder Path" | find /c ":\".

For example, we wanted to count the files and subfolders in our "E:\OneDrive\Documents" folder, so we had to run dir /a:-d /s /b "E:\OneDrive\Documents" | find /c ":\".

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 our example, that would be dir /a:d /s /b "E:\OneDrive\Documents" | find /c ":\".

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

4. How to count the files in a folder, using File Explorer

This method involves the use of File Explorer, but we left it until last 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 and browse 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

If you want to count only some of the files or folders stored inside your folder, select all of 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 number of selected items in a folder

That's it!

Do you know other methods to count the files in a folder?

If you want to know exactly how many files and folders are inside a folder from your Windows computer, now you know how to do it. As you've seen, there are a couple of ways to get this information, so you can choose whichever fits best. If you have questions, or if you know of other ways to find this information, don't hesitate to leave us a comment below.