Techibee.com

Use powershell to know the given path is absolute or relative

Sometimes while writing powershell scripts, you might get a need to verify if the given path is absolute(c:tempmyfolders) or relative(..myfolders). You can easily run this test by using one of the dotnet provided method, IsPathRooted(). This method returns TRUE if the given path is absolute and will return FALSE if the given path is relative.

 Below is one classic example…

c:>[System.IO.Path]::IsPathRooted("c:tempmyfolders")
True

c:>[System.IO.Path]::IsPathRooted("..myfolders")
False

 Note that this won’t check whether the path you provided exists or not. You can read more about this method at 

http://msdn.microsoft.com/en-us/library/system.io.path.ispathrooted.aspx

Exit mobile version