Check if a file or folder exists with Test-Path
The PowerShell true/false existence test every script should start with — supports files, folders, registry keys, and wildcards.
01Command
$ Test-Path 'C:\Program Files\Git\bin\git.exe'02What it does
Test-Path works on any PowerShell provider path: filesystem, registry (HKLM:\...), even environment variables. -PathType Leaf restricts the check to files and -PathType Container to folders, so you don't mistake a directory for the file you want. -IsValid checks only whether the path string is syntactically valid without touching the disk.
03Risk
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- Test-Path | Microsoft LearnEvidence: Microsoft documents Test-Path returning $True/$False for an existing path, plus -PathType Leaf/Container and -IsValid syntax checks.
- Test-Path - PowerShellEvidence: SS64 shows Test-Path examples including if (Test-Path ...) guards and the -IsValid parameter for validating path syntax.
Last verified: 2026-09-17 · 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.