As more and more items are stored on our computers, it is easy to lose count of how many items are contained in one folder. We have discussed in other articles limitations when it comes to folder sizes. While the likelihood of reaching 4,294,967,295 files in a folder is slim to none, there are times that we still need to know the number of files or subfolders within a folder.
If your folder only contains a small number of items, this can be easily done by opening the folder and subsequent subfolders and manually counting everything. However, if your folder has subfolders and those folders contain numerous subfolders themselves, counting manually can be tedious. This is where PowerShell comes in handy. By using a simple command, you can have your system automatically do the counting for you.
To do this you need to launch PowerShell. These steps assume that you have PowerShell set to be shown in the secondary Start menu. If not, look at this article explaining how to configure PowerShell to be shown.
(Get-ChildItem -Recurse | Measure-Object).Count
Related Commands
There are some slightly similar commands that might be useful as you're looking to count folder contents. To use these commands, just enter them instead of the command in step 4 above.
Get the count of the items only in the parent directory, does not return the counts of the subfolder elements:
Get-ChildItem | Measure-Object | %{$_.Count}
Count all the subfolders within a parent directory:
(Get-ChildItem -Recurse -Directory | Measure-Object).Count
Count all the files within a parent directory (even those within subfolders, without adding the subfolders to the count):
(Get-ChildItem -Recurse -File | Measure-Object).Count
Knowing these commands will help you determine the number of items within a parent folder. All much faster, and less tedious than counting manually.
This tip (13817) applies to Windows 10.
Every time a computer restarts, it runs through processes that help its performance. You can use PowerShell to see how ...
Discover MoreWhen you need your computer's serial number you can look it up without looking on the outside of the box. Use PowerShell ...
Discover MoreWi-Fi signal strength is important for faster, more consistent data transfers. You can use PowerShell to gain a more ...
Discover More2020-12-28 12:10:20
james
Eric,
Is there a way to call these PowerShell commands from Word VBA. If so, how would you do it? (some examples are always very helpful).
P.S. Thank you for you many tips along the way. Wishing you a very happy new year!
Copyright © 2024 Sharon Parq Associates, Inc.
Comments