如果我想将两个字符串组合成文件路径,我使用Join-Path
如下:
$path = Join-Path C: "Program Files"
Write-Host $path
Run Code Online (Sandbox Code Playgroud)
那打印"C:\Program Files"
.如果我想为两个以上的字符串执行此操作:
$path = Join-Path C: "Program Files" "Microsoft Office"
Write-Host $path
Run Code Online (Sandbox Code Playgroud)
Powershell抛出一个错误:
[string[]] $pieces = "C:", "Program Files", "Microsoft Office"
$path = Join-Path $pieces
Write-Host $path
Run Code Online (Sandbox Code Playgroud)
我尝试使用字符串数组:
C:\somepath
Program Files\somepath
Microsoft Office\somepath
Run Code Online (Sandbox Code Playgroud)
但是Powershell提示我输入子路径(因为我没有指定-childpath
参数),例如"somepath",然后创建三个文件路径,
$path = Join-Path C: "Program Files"
Write-Host $path
Run Code Online (Sandbox Code Playgroud)
哪个也不对.
powershell ×1