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:
dir "FilePath" /a:-d /s /b | find ":" /cÊ
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.
Displaying all the files a folder contains is an easy task in Windows. One way you can display the files is using command ...
Discover MoreIP addresses identify your device on IP-governed networks. If you need to find your IP address quickly, you can use the ...
Discover MoreThe copy command can be a timesaver over trying to do the similar sort of thing with Windows Explorer. You can copy ...
Discover More2021-01-04 20:48:16
Vince
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
Aussie--ii
What is the character "Ê" at the end of the command?
Commands worked well without it but gave "Invalid switch" with it.
Aussie--ii
Copyright © 2024 Sharon Parq Associates, Inc.
Comments