1

I don't understand why I cannot in PowerShell go into a folder with [], for example

cd c:\test\[demo] 

whereas I have created in PowerShell with

md [demo]

and I can actually cd with DOS command.

So what can I do if I want to navigate in this folder from PowerShell ?

phuclv
  • 37,963
  • 15
  • 156
  • 475
user310291
  • 36,946
  • 82
  • 271
  • 487
  • [DOS and cmd are very different](https://superuser.com/a/1411173/241386), don't use `dos` when using cmd – phuclv May 29 '22 at 13:05

1 Answers1

7

cd in PowerShell is an alias to Set-Location which receives a -Path by default if no option is specified. Almost all PowerShell commands that deal with files like Get-ChildItem, Get-Acl... use the FileSystem Provider and has -Path as a wildcard pattern where [] has special meaning. You'll need to escape those special characters like this

 cd '`[demo`]'

But cmdlets that receives wildcards also have -LiteralPath and that's the correct way to do

cd -LiteralPath [demo] # Or
cd -L [demo]
mklement0
  • 382,024
  • 64
  • 607
  • 775
phuclv
  • 37,963
  • 15
  • 156
  • 475