PowerShell: Path Expansion (get fullpath)
Some characters have special meaning in the value of Path
parameter.
Example:
~
at beginning → Same as$home
.
at beginning → Current dir. Same as(Get-Location)
..
at beginning → Parent dir.*
→ String Wildcards
Path will be “expanded”, to result in full path or multiple paths. This is called path expansion.
Path expansion happen after string expansion. [see PowerShell: String]
To see what a given path expand to, use
Resolve-Path
.
Resolve-Path
-
Resolves the wildcard characters in a path, prints result.
return a single object of
PathInfo
, or array of it. (return a string or array of string if Relative parameter is used.)
Resolve-Path ~/ # Path # ---- # C:\Users\xah
Resolve-Path "~/Documents/*" # Path # ---- # C:\Users\xah\Documents\PowerShell # C:\Users\xah\Documents\Wolfram Desktop # C:\Users\xah\Documents\wolframlang
Note: quoted path goes thru string expansion first, then go thru path expansion.
To not go thru path expansion, use parameter LiteralPath
.