Cricketer
Cricketer

Reputation: 409

How to change the directory to program files using Powershell?

I would like to open a C:\Program Files\R\R-3.2.0\bin\Rscript.exe. For that I am trying to change the directory. I figured that the error is in opening Program files. Following is the code

cd Program Files\R\R-3.2.0\bin

Error: A positional parameter cannot be found that accepts argument Files

Upvotes: 3

Views: 28244

Answers (3)

YvanTheComputerGuy
YvanTheComputerGuy

Reputation: 1

This was very helpful.

Because I was wondering why when I do Set-Location C:\Program Files, wasn't working.

Upvotes: 0

user2864740
user2864740

Reputation: 61975

Unlike command.com/cmd.exe, PowerShell follows much more consistent rules and in the failing case Program and Files\R..bin are parsed as two separate arguments, where the second is invalid in context (as cd only accepts a single non-named argument).

To fix this use quotes, eg.

 cd "C:\Program Files"

With the quotes it is parsed as a string value which is supplied as a single argument (the string itself does not include the quotes, again unlike cmd.exe rules).


FWIW, cd is an alias for Set-Location. Run get-help cd for the details on how it can be used - include which optional (and named) parameters it does support.

Upvotes: 8

briantist
briantist

Reputation: 47842

You need to put the path in quotes if it contains a space:

cd 'C:\Program Files\R\R-3.2.0\bin'

Either single or double quotes will work.

Upvotes: 1

Related Questions