Easily Counting Different Types of Files on Your Computer

There are a few ways you can count the specific types of files on a particular folder on your computer. For example, you can use the old school command line Dir with /s, or you can use the search feature in Windows 7 and 8. Or, you can use something even cooler that can not only count one specific type but many types at once.

Here is how you can achieve it using PowerShell, thanks to the Scripting Guy for the trick.

Basically, it uses the Get-ChildItem cmdlet to recursively scan a particular folder to retrieve specified types of files you want to count, and then pipe the results through to Group-Object cmdlet, with grouping on the Extension property with the -NoElement switch to remove the individual file information.

To simplify this, let’s just see an example that counts the number of files for JPG, PNG, TIF, DOC, and DOCX in my H: drive. Open PowerShell console and run the following command:

Get-ChildItem -Recurse -Include *.jpg, *.png, *.tif, *.doc, *.docx | Group-Object Extension -NoElement

Windows PowerShell - Get-ChildItem

Cool, easy, quick, and accurate. Don’t you agree?

Kent Chen

Microsoft MVP, IT Professional, Developer, Geek, and the co-founder of Next of Windows.

Last updated: 08/04/2014

Posted in: Tips & Tricks
Discover more: ,

Leave a Reply

Notify of
avatar
JimR
Guest

If for some reason you have to generate a report like this on a system where PowerShell isn’t available (.NET issues, old OS, etc.), you can generate a similar report using Microsoft’s LogParser. Contrary to its name, LogParser does more than read log files and can treat the file system as a database that can be accessed using SQL type queries.

But Powershell is so flexible……!

wpDiscuz
Today's Top Picks for Our Readers:
Recommended by Recommended by NetLine