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
I found through tab completion that you can escape the square brackets with backquotes:
test-path '.\a`[hi`]\'
move-item '.\a`[hi`]\' foo
set-location '.\a`[hi`]\'
-LiteralPath
insteadWhen 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\'