Test for File or Folder

by Dec 20, 2016

Test-Path can check whether a file or folder exists. If you add -PathType and specify Leaf (for files) or Container (for folders), the result can be even more specific:

$path = 'c:\windows'

Test-Path -Path $path
Test-Path -Path $path -PathType Leaf
Test-Path -Path $path -PathType Container

Twitter This Tip! ReTweet this Tip!