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:
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.
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.
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.
Next, let’s see how to use PowerShell to get the number of 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:
…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:
If you want to count the files and folders inside that directory, run this command:
Note that it does not work recursively; it only counts the first-level elements.
If you want to count only the folders inside your parent folder, run this command:
If you want to count only the files in the folder, run this command:
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
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.
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:
For example, to use CMD to count the files and subfolders in my "F:\OneDrive\Documents" folder, I need to run:
If you want to count the subfolders in a folder, run this command:
In my example, that would be:
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.
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.
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.
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.