How to access file paths in Powershell containing special characters?

前端 未结 3 869
感动是毒
感动是毒 2021-01-02 00:19

I am calling powershell from within a Java application (thru the Windows command prompt) to read various file attributes.

e.g.

powershell (get-item \         


        
3条回答
  •  情歌与酒
    2021-01-02 00:20

    This thread is 5 years old so maybe times have changed, but the current answer that worked for me was to use the backtick (`) symbol to escape the special character.

    In my case, it was a dollar sign in a directory path that was failing. By putting a backtick before the dollar sign, everything worked.

    Before:

    $dir = "C:\folder$name\dir"  # failed
    

    After:

    $dir = "C:\folder`$name\dir" # succeeded
    

提交回复
热议问题