I am now starting to use PowerShell and after a lot of time using the Unix shells and want to know how to check for the existence of a file or directory.
In Powershell why does Exist return false in the following expression?
PS H:\> ([System.IO.FileInfo]'C:\').Exists False
And is there a better way to check if a file is a directory than:
PS H:\> ([System.IO.FileInfo]'C:\').Mode.StartsWith('d') True
Use
Test-Pathinstead ofSystem.IO.FileInfo.Exists:You can also use
-PathTypeto test whether the location is a file or directory:DirectoryInfoandFileInfoalso both define aPSIsContainerproperty: