Skip to content

Howto count files in folders by file extension using PowerShell

Use Measure-Object to count things. In this case it would look like:

Only Files

Get-ChildItem c:\MyFolder -Recurse -File | Measure-Object | %{$_.Count}

Only Folders

Get-ChildItem c:\MyFolder -Recurse -Directory | Measure-Object | %{$_.Count}

Both

Get-ChildItem c:\MyFolder -Recurse | Measure-Object | %{$_.Count}

Specific files

Get-ChildItem -Path c:/MyFolder -Recurse -filter *.xml | Measure-Object -Property Directory
Published inWindows