July 14, 2026

How to Count Files in a Folder Using PowerShell

Counting how many files are in a folder is a quick task PowerShell handles neatly, which is helpful for verifying a transfer, checking a download, or reporting on folder contents. A short command returns the exact number.

The Command

(Get-ChildItem -File).Count

What It Does

`Get-ChildItem -File` lists the files in the current folder, the `-File` parameter ensuring folders are not counted. Wrapping it in parentheses and adding `.Count` returns just the number of items rather than the list itself. So YYGACOR this gives you a single number: how many files are in the folder.

When You’d Use This

This helps when verifying that a transfer or download completed with the expected number of files, checking how many items a folder holds before an operation, or reporting folder contents in a script. A quick count is more reliable than eyeballing a crowded folder, and the filter and recurse options let you count specific file types or include everything beneath a folder.

Useful Variations

To count files including all subfolders, add `-Recurse`: `(Get-ChildItem -File -Recurse).Count`. To count folders instead, use `-Directory`. To count only certain file types, add a filter, such as `(Get-ChildItem -Filter *.jpg -File).Count` for JPG files. To count files in another folder, add `-Path` with that folder.

If It Doesn’t Work

If the count seems too high, you may be counting folders as well, so ensure `-File` is included to count only files. If it seems too low, files might be in subfolders not being counted, so add `-Recurse` to include them. A count of zero means the folder is empty or the path is wrong, so confirm you are looking at the intended folder.

Good to Know

Without `-File`, the count includes both files and folders, so include it when you want files only. Adding `-Recurse` on a large folder tree can take a moment as it counts everything beneath, so expect a brief pause on big directories.

Putting It Together

Once you have run it once or twice, this becomes second nature. As part of managing files from the terminal, this command earns its place once you are comfortable working without File Explorer. Combined with the others in this area, it lets you handle files in bulk and in scripts far faster than clicking through folders. Like anything in the terminal, the real value comes from trying it on your own system and adapting the variations above to what you actually need, so it is worth experimenting with in a safe, low-stakes situation before relying on it in a script or during troubleshooting. Keeping a note of the commands you find most useful, along with the variations that fit your workflow, turns scattered one-off tricks into a personal reference you can draw on whenever a similar task comes up again.