Add double quotes to variable to escape space

后端 未结 4 1673
遇见更好的自我
遇见更好的自我 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:39

    fastest solution (but a bit ugly) to add quotes around any string:

    $dir = "c:\temp"
    $file = "myfile"
    $filepath = [string]::Join("", """", $dir,"\", $file, ".txt", """")
    

提交回复
热议问题