Anmol Parida
Anmol Parida

Reputation: 688

Changing directory in PowerShell to folder name containing Special Chars

I am currently at Users folder and want to get to Dockers folder.

I am not perform this due to the \OneDrive - xxxxx, zzz\

cd C:\Users\anmolparida\OneDrive - xxxxx, zzz\Work\Dockers\

Error

PS C:\Users> cd C:\Users\anmolparida\OneDrive - xxxxx, zzz\Work\Dockers\
Set-Location : A positional parameter cannot be found that accepts argument '-'.
At line:1 char:1
+ cd C:\Users\anmolparida\OneDrive - xxxxx, zzz\Work\Dockers\
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-Location], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

Upvotes: 0

Views: 1334

Answers (2)

HereToHelpAndLearn
HereToHelpAndLearn

Reputation: 46

cd 'C:\Users\anmolparida\OneDrive - xxxxx, zzz\Work\Dockers\'

Upvotes: 3

wasif
wasif

Reputation: 15518

Enclose it with single quotes:

cd 'C:\Users\anmolparida\OneDrive - xxxxx, zzz\Work\Dockers\'

Double quotes should work, too:

cd "C:\Users\anmolparida\OneDrive - xxxxx, zzz\Work\Dockers\"

If you don't use double quotes, then powershell takes them as separate arguments, so Set-Location fails, but when you quote regarded as value for single argument, -Path.

Upvotes: 0

Related Questions