153

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".

2
  • 1
    simple as this cd -Path Q:/
    – Omer
    Sep 19, 2020 at 12:20
  • For those that need to change directory temporarily, e.g. in a script, there's Push-Location and Pop-Location
    – djvg
    Nov 10 at 18:04

9 Answers 9

243

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.)

3
  • 14
    You have to enclose the path in "" otherwise it will give you error. Command will look like this Set-Location "Q:\My Test Folder"
    – Asad
    Apr 26, 2018 at 12:30
  • 3
    @Asad - Good point, and one that I should have included originally, though quoting is only necessary if the path contains spaces. Apr 26, 2018 at 12:34
  • cmd.exe supports "cd /d e:\somedirectory" to also switch drives Dec 18, 2021 at 15:30
39

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

Set-Location "Q:\My Test Folder"
0
28

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 "".

2
  • 10
    Single quotes will work as well, e.g., Set-Location 'C:\Path With Spaces' Mar 28, 2018 at 14:37
  • 7
    double inverted commas 🤦‍♂️ Aug 21, 2020 at 11:35
25

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

5
  • 1
    It doesn't seem to work. Am I doing this correctly? PS C:\> Q:
    – SoConfused
    Dec 13, 2016 at 20:57
  • Are you sure it's there? I guess if it's Q:/ drive that that is some sort of removable media, it is maybe something as simple as plugging it in. Dec 13, 2016 at 21:00
  • 1
    The assumption is that the drive Q does in fact exist. If it does not, PowerShell will throw an error specifying that the drive does not exist. Dec 13, 2016 at 21:01
  • Oh, yeah, my bad. Dec 13, 2016 at 21:04
  • 3
    Love simple solutions :)
    – Heike
    Sep 25, 2019 at 14:11
13
Set-Location -Path 'Q:\MyDir'

In PowerShell cd = Set-Location

2
  • 12
    This must be one of the worlds best reason not to use Powershell.
    – not2qubit
    Dec 5, 2018 at 16:41
  • 1
    Since aliases can be removed and redefined, I will always use the expanded cmdlet in answers here - I can't assume that just because I haven't removed or changed the cd alias, neither have you. Oct 3, 2020 at 15:29
4

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:\
2

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

1

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

0
  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'

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.