Count Files in a Folder with PowerShell

Count files (optionally recursively through subfolders) with Get-ChildItem and Measure-Object on Windows.

WindowsdirectoriesFilescountingpowershellLow risk
Run (Get-ChildItem 'C:\folder' -Recurse -File | Measure-Object).Count — drop -Recurse to count only the top level.

01Command

Command
$ (Get-ChildItem 'C:\Users\me\Downloads' -File).Count
(Get-ChildItem 'C:\Users\me\Downloads' -Recurse -File | Measure-Object).Count

02What it does

The .Count of the Get-ChildItem result is enough for a single folder, while piping into Measure-Object gives a count plus other stats in one pass. Add Measure-Object Length -Sum to get the total size at the same time, or -Directory instead of -File to count subfolders. In cmd, dir /a-d /s /b 'C:\folder' | find /c /v "" counts every file recursively.

03Risk

RiskLow risk

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • Measure-Object
    Microsoft Learn · vendor-doc · 2026-09-17
    Evidence: Measure-Object counts piped objects, giving file totals for Get-ChildItem output.
  • Measure-Object - SS64
    SS64 · technical · 2026-09-17
    Evidence: Shows using Measure-Object to count files and sum numeric properties such as Length.

Last verified: 2026-09-18 · Category: Files & Folders

06Related solutions