Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the directory to program files using Powershell?

Tags:

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
like image 326
Cricketer Avatar asked Mar 01 '26 14:03

Cricketer


1 Answers

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.

like image 91
user2864740 Avatar answered Mar 04 '26 22:03

user2864740



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!