Issue with path containing [ and ( when using -Path

前端 未结 2 1541

I try to write a script with PowerShell to move 3 folders. I\'ve got some issue due to the different [] and () in my path. I can\'t change the path

2条回答
  •  一生所求
    2020-12-12 02:36

    Use -LiteralPath instead

    When you use -Path with the Item/ChildItem provider cmdlets, PowerShell treats the argument as a potential wildcard pattern!

    Since [A-Z] is a wildcard pattern construct, the file system globber won't actually resolve file(s) with a literal [ or ] in the name.

    Using -LiteralPath will supress any attempt to expand wildcards:

    Test-Path -LiteralPath "D:\Program Files (x86)\Steam\steamapps\common\Stardew Valley\Mods\[TMX] IF2 Red Shed"
    

    Remember to quote paths with spaces as well!

    Move-Item -LiteralPath 'C:\path with [wildcards]\in\the\name.ext' -Destination 'C:\Destination\path\'
    

提交回复
热议问题