Commands / Files

Test-Path

Check whether a path exists

beginner Files

Test-Path
 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

ShellWhat you might type
bash / zshtest -e docs && echo yes
cmd.exeif exist docs echo yes

More in From bash and From cmd.

Related commands