Table of Contents
There may be times when we need to know how to Count Files in Folder or a Directory. This kind of information is especially important for automation and keeping statistics up to date. No matter what the reason is, if there are a lot of files in the folder, counting them by hand will take a long time. Windows has many ways to help its users keep track of the count.
That can be hard, especially if there are a lot of files saved in subfolders inside subfolders inside subfolders. They are too many to count by hand. The count function is an array function that counts the number of items in an array or object. We mentioned below are the ways to Count Files in Folder or a Directory. You can also go to the official Microsoft support site for more information about this error.
ways to Count Files in Folder or a Directory
Using PowerShell
If you want to count folders and/or files in your parent folder in a way that goes back into them, add the Recurse parameter to the commands above, as shown below:
- 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“.
- 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 File Explorer
Do you want to count all the folders and files in a certain folder and all its subfolders? Using the folder’s Properties window is an easy way to find this information.
- Open File Explorer, find the folder you want to change, and right-click or press and hold on the icon of the folder.
- Choose Properties from the menu that pops up. You can also choose the folder and press Alt + Enter on your keyboard.
- Windows 11/10 automatically starts counting the files and folders in the selected directory when the Properties window opens.
- In the Contains field, you can see how many files and folders are shown.
Using Command Prompt (cmd)
- 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 “:”.
- 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 “:”.
FAQ
How can you count number of files and folders in your current directory?
Start up Windows Explorer. Go to the folder where the files you want to count are stored. The number of files and folders in the current directory is shown in the bottom left corner of the window.
What is the command to count number of files in a directory in Windows?
Open the folder and choose all of the subfolders or files by hand or by pressing the CTRL+A keyboard shortcut. If you choose by hand, you can pick and leave out certain files. Near the left bottom of the window, you can now see the total count.
How many files can exist in a folder?
You can put 4,294,967,295 files in a single folder if the drive is formatted with NTFS (it would be rare if it wasn’t), as long as you don’t go over 256 terabytes (the size and space of a single file) or all of the available disc space, whichever is less.
Which command is used to count the number of file?
Use the wc command to count the number of lines, words, and bytes in the file specified by the File parameter. If the File parameter is not given a file name, the standard input is used. The command sends the results to the standard output and keeps track of how many times each named file was counted.