Count Files in a Folder with PowerShell
Count files (optionally recursively through subfolders) with Get-ChildItem and Measure-Object on Windows.
01Command
$ (Get-ChildItem 'C:\Users\me\Downloads' -File).Count
(Get-ChildItem 'C:\Users\me\Downloads' -Recurse -File | Measure-Object).Count02What 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
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- Measure-ObjectEvidence: Measure-Object counts piped objects, giving file totals for Get-ChildItem output.
- Measure-Object - SS64Evidence: Shows using Measure-Object to count files and sum numeric properties such as Length.
Last verified: 2026-09-18 · Category: Files & Folders
06Related solutions
Diagnose NTFS file system errors and bad sectors on any volume — including the system drive while Windows is running — before committing to a repair.
Robocopy is Windows' built-in robust file copier: use /MIR to keep a destination folder as an exact one-way mirror of a source, resumable and restartable.
Search inside text files and logs with regex, returning file, line number and match.