【发布时间】:2020-02-26 02:29:15
【问题描述】:
如何将此路径与此变量连接?
$file = "My file 01.txt" #The file name contains spaces
$readfile = gc "\\server01\folder01\" + ($file) #It doesn't work
谢谢
【问题讨论】:
标签: powershell
如何将此路径与此变量连接?
$file = "My file 01.txt" #The file name contains spaces
$readfile = gc "\\server01\folder01\" + ($file) #It doesn't work
谢谢
【问题讨论】:
标签: powershell
有几种方法。最简单的:
$readfile = gc \\server01\folder01\$file
你的方法很接近:
$readfile = gc ("\\server01\folder01\" + $file)
您也可以使用Join-Path 例如:
$path = Join-Path \\server01\folder01 $file
$readfile = gc $path
【讨论】:
Join-Path 更好。所以你看到发生了什么,我不知道“gc”做了什么。这就是我使用 -> Join-Path -Path "path" -ChildPath "childpath" 的原因