Not able to change directory in powershell

-1

0

cd  C:\Users\Rupesh Kumar\Documents

There is a space between "Rupesh Kumar" which doesn't allow me to change the directory but it is working in CMD.

Set-Location : A positional parameter cannot be found that accepts argument 'Kumar\Desktop'.
At line:1 char:1
+ cd C:\Users\Rupesh Kumar\Desktop
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-Location], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

green seek

Posted 2019-10-12T03:36:33.947

Reputation: 1

This just says you are just starting with PowerShell, so, please be sure to spend the needed time leading it first, to limit / eliminate confusion, misconception, bad code, errors, etc... YouTube is your friend https://www.youtube.com/results?search_query=powershell+file+and+folder+management as well as the tons of free no cost guidance, training available all over the web. Always use full PowerShell cmdlet / function names and parameters. Shorthand / aliases like you are using are fine for interactive stuff, but not scripts, and you are still bound by what PowerShell expects.

– postanote – 2019-10-14T00:32:57.013

Answers

1

In cmd cd is an internal command that receives an optional /D option and then treats the whole remaining command line as path, therefore it accepts spaces in the paths even without quotes. Just run cd /? and you'll see

CHDIR command does not treat spaces as delimiters, so it is possible to
CD into a subdirectory name that contains a space without surrounding
the name with quotes.  For example:

    cd \winnt\profiles\username\programs\start menu

In powershell cd is just an alias to Set-Location which accepts various parameters, one of which is the path. You can't have raw spaces in a single argument like almost all other shells, therefore you must quote it or escape the spaces like this

cd 'C:\Users\Rupesh Kumar\Documents'
cd "C:\Users\Rupesh Kumar\Documents"
cd C:\Users\Rupesh` Kumar\Documents

cmd and powershell are completely different terminals, so why do you expect them to behave the same?

phuclv

Posted 2019-10-12T03:36:33.947

Reputation: 14 930

0

Please add single quotes for the set-location as directed above. As a coder I tend to avoid spaces if I can in everything I write in code. I opt for _ or simply capitalize with no space

German Cito Altgelt

Posted 2019-10-12T03:36:33.947

Reputation: 1