Test-Path
Check whether a path exists
Test-Path -Path .\docs
- Works on
- WindowsLinuxmacOS
- PowerShell
- 5.1 and later
- Reference
- Microsoft Learn: Test-Path
Returns $true or $false. Use it before you copy, move, or delete.
-PathType Leaf means "this is a file". -PathType Container means "this is a folder".
Try this
if (Test-Path -Path .\docs -PathType Container) { 'Folder exists' }
Coming from another shell
| Shell | What you might type |
|---|---|
| bash / zsh | test -e docs && echo yes |
| cmd.exe | if exist docs echo yes |
More in From bash and From cmd.