How to normalize a path in PowerShell?

后端 未结 12 2093
半阙折子戏
半阙折子戏 2020-12-05 03:53

I have two paths:

fred\\frog

and

..\\frag

I can join them together in PowerShell like this:



        
12条回答
  •  暖寄归人
    2020-12-05 04:17

    You could also use Path.GetFullPath, although (as with Dan R's answer) this will give you the entire path. Usage would be as follows:

    [IO.Path]::GetFullPath( "fred\frog\..\frag" )
    

    or more interestingly

    [IO.Path]::GetFullPath( (join-path "fred\frog" "..\frag") )
    

    both of which yield the following (assuming your current directory is D:\):

    D:\fred\frag
    

    Note that this method does not attempt to determine whether fred or frag actually exist.

提交回复
热议问题