Counting the Number of Files or Subfolders Using PowerShell

Written by Eric Wyatt (last updated December 28, 2020)


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.

  1. Right-click on the Start button. Windows displays the secondary Windows Start menu.
  2. Choose Windows PowerShell. Windows opens a PowerShell window.
  3. Enter the file structure to the folder you're wanting to check by entering "cd" (without quotes) followed by the folder location. Hint: after entering "cd" (again, without quotes) add a space and then drag the folder you want to look at the PowerShell window. Windows places the correct folder path for you. Then press Enter. You will see "PS C:\FILEPATH"Ê
  4. Enter the following command and press Enter. This counts all the files or subfolders within the parent folder you specified:
  5. (Get-ChildItem -Recurse | Measure-Object).Count
  6. Windows returns the number of all the files and subfolders.Ê
  7. When done, close the PowerShell window.

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.

Author Bio

Eric Wyatt

Eric Wyatt is a swell guy (or so his friends tell him). He is a formally trained designer and branding expert, bringing a wide range of skills to his Tips.Net articles. ...


Move the Windows 11 Taskbar to the Left

Windows 11's new Taskbar puts the Start menu and apps front and center. In this tip you learn how to move the Taskbar to ...

Discover More

Enable Edge's Kids Mode

The internet is full of age-inappropriate content. You can use Edge's built-in Kids Mode to protect young ones from ...

Discover More

Adjusting Print Margins in Microsoft Edge

Printing hard copies of web pages can be difficult when you want the printout to have margins suitable for storing the ...

Discover More
More WindowsTips

Passing Parameters to a PowerShell Script

Like the older batch-file processor, PowerShell can accept parameters. This allows for flexibility in your script. This ...

Discover More

Change your Computer's Name with PowerShell

Your computer has a name that is separate from your account name. You can use PowerShell to change the name of your computer.

Discover More

Using PowerShell to Find Your Wireless Signal Strength

Wi-Fi signal strength is important for faster, more consistent data transfers. You can use PowerShell to gain a more ...

Discover More

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 5 - 0?

2020-12-28 12:10:20


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!

Newest Tips