Add double quotes to variable to escape space

后端 未结 4 1676
遇见更好的自我
遇见更好的自我 2020-12-20 22:02

I am running a script which has $FileName variable containing the absolute path with spaces. Due to the space within the directory name and file name, the script fails to ex

4条回答
  •  情书的邮戳
    2020-12-20 22:48

    Any one of these should work:

    $FilePath1 = """" + (Join-Path $Path $($Dir + "\" + $File + ".txt")) + """"
    $FilePath2 = "`"" + (Join-Path $Path $($Dir + "\" + $File + ".txt")) + "`""
    $FilePath3 = '"{0}"' -f (Join-Path $Path $($Dir + "\" + $File + ".txt"))
    $FilePath4 = '"' + (Join-Path $Path $($Dir + "\" + $File + ".txt")) + '"'
    $FilePath5 = [char]34 + (Join-Path $Path $($Dir + "\" + $File + ".txt")) + [char]34
    

提交回复
热议问题