SoConfused
SoConfused

Reputation: 1989

Change directory in PowerShell

My PowerShell prompt's currently pointed to my C drive (PS C:\>). How do I change directory to a folder on my Q (PS Q:\>) drive?

The folder name on my Q drive is "My Test Folder".

Upvotes: 166

Views: 846830

Answers (9)

gluttony
gluttony

Reputation: 569

I don't know why everyone talks about Set-Location and the fact that cd does not change drive and directory, in fact it actually does it (in powershell, not cmd), you just need to put quotes (single or double) around if there are spaces in folder name(s), also you can just type drive letter if you just want to go to its root:

enter image description here

Edit: now I started editing my PowerShell scripts with a "real" IDE I understood why everyone talks about Set-Location, cd is just an alias to it:

enter image description here

Upvotes: 3

Monika
Monika

Reputation: 431

  1. On Powershell use Set-Location instead of cd.
  2. Put path in quotes. Single quotes works for me.

Set-Location 'C:\Program Files\MongoDB\Server\6.0'

Upvotes: 0

cpeaustriajc
cpeaustriajc

Reputation: 361

You can also use the sl command to be able to change directories. It is Set-Location but it is much shorter.

Example:

# Too verbose
Set-Location -Path C:\

# Just the right amount of characters to type
sl C:\

Upvotes: 4

Rao Adnan
Rao Adnan

Reputation: 1647

Set-Location -Path 'Q:\MyDir'

In PowerShell cd = Set-Location

Upvotes: 13

Sibasis Mohanty
Sibasis Mohanty

Reputation: 11

If your Folder inside a Drive contains spaces In Power Shell you can Simply Type the command then drive name and folder name within Single Quotes(''):

Set-Location -Path 'E:\FOLDER NAME'

The Screenshot is attached here

Upvotes: 1

Jeff Zeitlin
Jeff Zeitlin

Reputation: 10764

Unlike the CMD.EXE CHDIR or CD command, the PowerShell Set-Location cmdlet will change drive and directory, both. Get-Help Set-Location -Full will get you more detailed information on Set-Location, but the basic usage would be

PS C:\> Set-Location -Path Q:\MyDir

PS Q:\MyDir> 

By default in PowerShell, CD and CHDIR are alias for Set-Location.

(Asad reminded me in the comments that if the path contains spaces, it must be enclosed in quotes.)

Upvotes: 259

Deepesh
Deepesh

Reputation: 610

Multiple posted answer here, but probably this can help who is newly using PowerShell

enter image description here

SO if any space is there in your directory path do not forgot to add double inverted commas "".

Upvotes: 29

BenH
BenH

Reputation: 10034

To go directly to that folder, you can use the Set-Location cmdlet or cd alias:

Set-Location "Q:\My Test Folder"

Upvotes: 44

Cordo van Saviour
Cordo van Saviour

Reputation: 600

You can simply type Q: and that should solve your problem.

Upvotes: 27

Related Questions