Add double quotes to variable to escape space

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

    In addition to the backtick escape character (`), you can use the -f format operator:

    $FilePath = Join-Path $Dir -ChildPath "$File.txt"
    $FilePathWithQuotes = '"{0}"' -f $FilePath
    

    This will ensure that $FilePath is expanded before being placed in the string

提交回复
热议问题