Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert relative path to absolute path in PowerShell?

Tags:

powershell

How to convert relative path to absolute path in PowerShell?

$path1 = C:/1/2/3/
$parth2 = ../../base/
=====
$result = C:/1/base/
like image 515
Artem Yukhimenko Avatar asked Jan 24 '26 08:01

Artem Yukhimenko


2 Answers

(Join-Path $path1 $path2) | Resolve-Path
like image 141
Artem Yukhimenko Avatar answered Jan 26 '26 23:01

Artem Yukhimenko


If your path is not existent yet, most of the above will blow up on you.

Either of the following will work even if the path doesn't exist yet:

[IO.Path]::GetFullPath(".\abc")
$ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath(".\abc.txt")
like image 35
Doug Avatar answered Jan 26 '26 22:01

Doug



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!