How can I open a cmd window in a specific location?

WindowsCmd

Windows Problem Overview


How can I open a cmd window in a specific location without having to navigate all the way to the directory I want?

Windows Solutions


Solution 1 - Windows

This might be what you want:

cmd /K "cd C:\Windows\"

Note that in order to change drive letters, you need to use cd /d. For example:

C:\Windows\System32\cmd.exe /K "cd /d H:\Python\"

(documentation)

Solution 2 - Windows

If you have Windows Vista or later, right-click on the folder icon in Explorer while holding the Shift key, and then click on the "Open command window here" or "Open PowerShell window here" context menu option.

If you're already in the folder you want, you can do one of the following:

  • [only Win8+] Click the Explorer Ribbon's File button, then click on "Open command window here" or "Open PowerShell window here".
  • Shift-right-click on the background of the Explorer window, then click on "Open command window here" or "Open PowerShell window here". (recommended by Kate in the comments)
  • [only Vista or Win7] Hold down Shift when opening the Explorer File menu, then click on "Open command window here". If you can't see the menu bar, open the File menu by pressing Alt-Shift-F - Alt-F to open the File menu, plus Shift.

For Windows XP, use the PowerToy mentioned by dF to get the same function.

Solution 3 - Windows

Assuming that in File Explorer you have opened the target directory/folder, do this:

  1. Click on address bar, alternatively press Alt+D

  2. Now when address bar is highlighted, type cmd in the bar.

  3. Press Enter key

You will notice that command prompt from that folder

Solution 4 - Windows

From Windows 7 up to some versions of Windows 10, it is very simple to open a command prompt anywhere you wish, without navigation using command "cd". Try the following one. Click the mouse's right button by holding Shift key .

Sample

It will produce an option like this. Then simply select the "Open command window here " option. The latest versions of Windows 10 have replaced this feature with "Open Powershell here".

Solution 5 - Windows

Try out this "PowerToy" from Microsoft:

> Open Command Window Here > > This PowerToy adds an "Open Command > Window Here" context menu option on > file system folders, giving you a > quick way to open a command window > (cmd.exe) pointing at the selected > folder.

EDIT : This software will not work on any version of Windows apart from Windows XP.

enter image description here

Solution 6 - Windows

On Windows Vista, Windows 7 and Windows 10 simply hold down the Shift key and right-click on a folder.

The context menu will contain an entry titled: "Open command window here"

Update: Type "cmd" in the address bar of Explorer and press enter

enter image description here

Update 2: In windows 10, go to file menu and select "Open Windows PowerShell". There is an option for running as administrator.

enter image description here

Solution 7 - Windows

Use the /K switch. For example

cmd /K "cd /d c:\WINDOWS"

Will create a cmd window at the C:\Windows directory

Solution 8 - Windows

Just write cmd in the address bar, it will open in the current folder.

Solution 9 - Windows

In windows go to folder location in file explorer remove path and type cmd and press enter. and path will open in cmd.

Solution 10 - Windows

Also, here is a shortcut to open a console in any windows folder:

  • Open any folder on windows explorer.
  • Press Alt + D to focus the adress bar
  • type cmd and press enter

Very practical shortcut.

Solution 11 - Windows

If you are starting cmd from taskbar, this is what you need to do:

right click --> rightclick on Command Prompt --> Properties

enter image description here

Then in the properties window change the value of Start in:

enter image description here

This solution doesn't work for opening command prompt as administrator

Solution 12 - Windows

Create a shortcut and edit the "Start In" property of the shortcut to the directory you want the cmd.exe to start in.

Solution 13 - Windows

In Windows 8, you can click the address bar and type "cmd" (without quotes) and hit enter. This will open the cmd window in the current path.

Solution 14 - Windows

Easiest way is to goto the address bar of the Windows Explorer and type cmd there. It will automatically open the command prompt window for you.

Solution 15 - Windows

I just saw this question and cannot help to post my AutoHotkey script for cmd on Windows XP. You can spot the hot keys in the script. The nice thing is when your current windows is Explorer, the cmd will open in the path showing in the address bar.

I keep this script in a folder where I store all green tools (including AutoHotkey). For a new machine, I just copy the folder, double click the script to associate .ahk with AutoHotkey and create a shortcut in my startup folder. It is faster than installing PowerToys.

; Get working folder
GetWorkingFolder() {
    if WinActive("ahk_class ExploreWClass") or WinActive("ahk_class CabinetWClass") {
        ControlGetText, path, Edit1
        return %path%
    } else if WinActive("FreeCommander") {
        Send, {CTRLDOWN}{ALTDOWN}{INS}{ALTUP}{CTRLUP}
        Sleep, 100
        return clipboard
    } else {
        return "C:\"
    }
}

#IfWinActive,

#c::
    path := GetWorkingFolder()
    Run, %ComSpec%, %path%
    return

; PowerShell
#+C::
    path := GetWorkingFolder()
    Run, %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe, %path%
    return

#^c::
    Run, %ComSpec%, %temp%
    return

#!c::
    path := GetWorkingFolder()
    Run, %comspec% /k "%VS90COMNTOOLS%vsvars32.bat", %path%
    return

; irb
#!b::
    path := GetWorkingFolder()
    Run, c:\cygwin\bin\ruby /usr/bin/irb, %path%
    return

; Bash
#b::
    path := GetWorkingFolder()
    Run, bash --login, %path%
    return

; Paste in console
+INS::
    if WinActive("ahk_class ConsoleWindowClass") {
        WinGetPos, x, y, w, h, A
        MouseGetPos, mx, my
        ;MsgBox x=%x% y=%y% w=%w% h=%h% mx=%mx% my=%my%
        if (mx < 10)
            mx = 10
        else if (mx > w - 30)
            mx := w - 30

        if (my < 40)
            my = 40
        else if (my > h)
            my := h - 10

        MouseClick, right, mx, my
    }
    return

For anyone who is interested, you can find this script at rwin on github

Solution 16 - Windows

Update: This is built into Windows now. See this answer.

The XP powertoy is a good option, but I thought I'd post another, in case you'd like to "roll your own". Create a text file, name it anything.reg, paste in the code below, save it, then double-click on it to add it to the registry (or just add the info to the registry manually if you understand what's going on in this .reg file).

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Folder\shell\Command_Prompt_Here...]
@="Command Prompt Here..."

[HKEY_CLASSES_ROOT\Folder\shell\Command_Prompt_Here...\command]
@="cmd.exe \"%1\""

Update: After an Windows-update, Win10 removed the cmd-here feature. To reactivate it you've to use:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\cmd]
@="@shell32.dll,-8506"
"Extended"=""
"NoWorkingDirectory"=""
"ShowBasedOnVelocityId"=dword:00639bc8

[HKEY_CLASSES_ROOT\Directory\shell\cmd\command]
@="cmd.exe /s /k pushd \"%V\""

The entry ShowBasedOnVelocityId is mandatory

Solution 17 - Windows

This will add entries to the context-menu to launch a command window that is automatically navigated to the directory you clicked.

Usage:

Right-click a folder icon (or the empty background area inside an already open folder)
and click either "Open in Terminal" or "Open in Terminal (Admin)".

You can also right click files to execute them with a command window.
When the file is done running you are left with a command window that is navigated to the files directory.

enter image description here

Open_in_Terminal.reg

Windows Registry Editor Version 5.00

; Admin versions.

; Right click on a folder in a directory.
[HKEY_CLASSES_ROOT\Directory\shell\OpenCommandWindowHereAsAdministrator]
@="Open in Terminal (Admin)"
"Icon"="cmd.exe"
"HasLUAShield"=""
"Position"="middle"
[HKEY_CLASSES_ROOT\Directory\shell\OpenCommandWindowHereAsAdministrator\command]
@="cmd.exe /c powershell.exe -Command \"Start-Process cmd -Verb runas -ArgumentList '/k pushd \"%1\"'\""

; Right click on nothing in a directory, i.e. the "background" of the directory.
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCommandWindowHereAsAdministrator]
@="Open in Terminal (Admin)"
"Icon"="cmd.exe"
"HasLUAShield"=""
"Position"="middle"
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCommandWindowHereAsAdministrator\command]
@="cmd.exe /c powershell.exe -Command \"Start-Process cmd -Verb runas -ArgumentList '/k pushd \"%V\"'\""

; Right click on nothing in a library directory, i.e. the "background" of the library directory.
[HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\OpenCommandWindowHereAsAdministrator]
@="Open in Terminal (Admin)"
"Icon"="cmd.exe"
"HasLUAShield"=""
"Position"="middle"
[HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\OpenCommandWindowHereAsAdministrator\command]
@="cmd.exe /c powershell.exe -Command \"Start-Process cmd -Verb runas -ArgumentList '/k pushd \"%V\"'\""

; Right click on a file in a directory.
[HKEY_CLASSES_ROOT\*\shell\OpenWithCommandWindowAsAdministrator]
@="Open in Terminal (Admin)"
"Icon"="cmd.exe"
"HasLUAShield"=""
"Position"="middle"
[HKEY_CLASSES_ROOT\*\shell\OpenWithCommandWindowAsAdministrator\command]
@="cmd.exe /c powershell.exe -Command \"Start-Process cmd -Verb runas -ArgumentList '/k pushd \\\"%W \\\" && \\\"%1\\\"'\""

; Non-Admin versions.

; Right click on a folder in a directory.
[HKEY_CLASSES_ROOT\Directory\shell\OpenCommandWindowHere]
@="Open in Terminal"
"Icon"="cmd.exe"
"Position"="middle"
[HKEY_CLASSES_ROOT\Directory\shell\OpenCommandWindowHere\command]
@="cmd.exe /k pushd \"%1\""

; Right click on nothing in a directory, i.e. the "background" of the directory.
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCommandWindowHere]
@="Open in Terminal"
"Icon"="cmd.exe"
"Position"="middle"
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCommandWindowHere\command]
@="cmd.exe /k pushd \"%V\""

; Right click on nothing in a library directory, i.e. the "background" of the library directory.
[HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\OpenCommandWindowHere]
@="Open in Terminal"
"Icon"="cmd.exe"
"Position"="middle"
[HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\OpenCommandWindowHere\command]
@="cmd.exe /k pushd \"%V\""

; Right click on a file in a directory.
[HKEY_CLASSES_ROOT\*\shell\OpenWithCommandWindow]
@="Open in Terminal"
"Icon"="cmd.exe"
"Position"="middle"
[HKEY_CLASSES_ROOT\*\shell\OpenWithCommandWindow\command]
@="cmd.exe /k pushd \"%W\" && \"%1\""

This took a lot of effort to make so if you're feeling generous then feel free to send a paypal donation to help me overcome the PTSD of debugging and testing it :)

An uninstaller if you need one:

Open_in_Terminal_Remover.reg

Windows Registry Editor Version 5.00

[-HKEY_CLASSES_ROOT\Directory\shell\OpenCommandWindowHereAsAdministrator]
[-HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCommandWindowHereAsAdministrator]
[-HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\OpenCommandWindowHereAsAdministrator]
[-HKEY_CLASSES_ROOT\*\shell\OpenWithCommandWindowAsAdministrator]
[-HKEY_CLASSES_ROOT\Directory\shell\OpenCommandWindowHere]
[-HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCommandWindowHere]
[-HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\OpenCommandWindowHere]
[-HKEY_CLASSES_ROOT\*\shell\OpenWithCommandWindow]

Solution 18 - Windows

pushd command sets the current folder. so:

cmd /k "pushd D:\Music"

Solution 19 - Windows

For windows 7 or later, inside the target folder address bar just type cmd. That is it. It will open up command prompt with path set to your present directory.

Solution 20 - Windows

This answer is for windows 10.

Create a command prompt shortcut in the folder wherever you want, then right click on that shortcut type your target in start in field

and

Here you go

Solution 21 - Windows

In File Explorer, press and hold the Shift key, then right click or press and hold on a folder or drive that you want to open the command prompt at that location for, and click/tap on Open Command Prompt Here option.

Solution 22 - Windows

I see that there are multiple answers, some are quite complex :) , strange to see them. You just have to open any windows folder window, navigate to your desired folder and focus on address bar and enter "cmd" and press enter, you would be presented with new command prompt window directly with the folder path or location that we already navigated in windows folder window. In case you want to see these steps with clear images you can check out

how to open command prompt in a specific folder directly

Solution 23 - Windows

For windows : Select the folder which you want to open in command prompt - After selection, Keeping the 'Shift key' pressed. Right click there and choose option "open command window here"

Solution 24 - Windows

Make the shortcut to cmd.exe with params /S /K pushd "C:\YOUR FOLDER"

Solution 25 - Windows

In Windows go to the specific folder, then click on the file explorer path and remove it then type cmd and click enter.. and in cmd your specific folder with its path will open..

Solution 26 - Windows

In Windows Explorer - shift + right mouse click above folder "Open command window here" option show up in the menu. Or in language of your Windows version.

Solution 27 - Windows

Right click the desktop and navigate to new and then from the sub-menu select "shortcut" → Browse to the Windows directory (or folder) and then to the system32 directory and click OK.

Add a \ and "cmd.exe" (without the quotes) to the command string. It should look like this:

C:\WINDOWS\System32\cmd.exe.

Click Next and Finish. Right click the new CMD icon on your desktop and select properties, and Next to the Start. In options, delete the line and add the path to wherever the directory is that you want it to start in... For example, C:\temp\mp3 and click OK.

Solution 28 - Windows

There is a simplier way I know. Find cmd.exe in start menu and send it to Desktop as shortcut. Then right-click it and choose properties. You will see "Start in" box under the "Target". Change that directory as whatever you'd like to set. Click OK and start cmd.exe which is in your Desktop. In my opinion, it's a very easy and certain solution :)

Solution 29 - Windows

This program always opens cmd.exe in the current path of your Explorer: https://github.com/jhasse/smart_cmd

You can also pin it to your taskbar and then use WindowsKey+[1-0] as a keyboard shortcut.

Solution 30 - Windows

With a Just-one-line file in batch:

START "Desire_Path" // Without quotes puth the location that you want to start in with cmd

Example (Open a text editor, place the code in there and save the file with a .bat extension):

START cd C:\Users

Then just double click on it

****Note: if you want the explorer to complete the task don´t put the CD command.

*To do the opossite:

In order for you to open a particular directory with the explorer.exe aplication while using cmd you can use the command START and the absolute route of the folder that you want to display.

Solution 31 - Windows

This method is using cmd.exe and Send to shortcut so cmd.exe can open directory directly. This alternative method is in case of not having Open command window here in right click menu.

  1. Open 'File Explorer' and enter shell:sendto in location bar to navigate to Send to folder.
  2. Copy a Command Prompt shortcut or create a new shortcut .lnk file.
  3. Edit the properties of the shortcut and edit the target to %windir%\system32\cmd.exe /k cd /d and press 'OK' to save the change.
  4. Right click on a folder and expand Send to menu to use the cmd shortcut.

This shortcut should open a cmd window with directory selected by the right click.

This method should work under Window 7 and 10 at least. Name the shortcut as Command Prompt (cd) to specify the task of the shortcut.

Possible error messages:

  • Show 'The directory name is invalid.' if other than folder is selected.
  • Show 'The system cannot find the drive specified.' if the folder is not existed.
  • Show 'The filename, directory name, or volume label syntax is incorrect.' if multiple files are selected.

Little about shortcut: The directory would be automatically added to the end of the shortcut as a parameter when using under Send to, so the shortcut does not need to type in the directory.

Solution 32 - Windows

In my case I VERY SPECIFICALLY wanted an opened CMD window in ADMIN mode in a specific folder. Here's how (works for Windows 7):

In the target folder, create START.BAT that simply contains one line:

  start cd c:\MyTargetFolder

Drag a shortcut from START.BAT and call it "START AS ADMIN".

Right-click the shortcut and select "Run as Administrator" and "Run Minimized". Also make sure that the "Start In" will cause the same drive to be selected (as CD does not change the drive!).

When you click on that shortcut you will get the UAC prompt and then an open command window in the desired folder. The title bar will show that this CMD window is in ADMINISTRATOR mode.

Solution 33 - Windows

<===||==========> On Windows 10 <==========||===>


Assuming that in File Explorer you have opened the target directory/folder, do this :

  1. Click on address bar, alternatively press Alt + A

  2. Now when address bar is highlighted, type cmd in the bar.

  3. Press Enter key


For a powershell window :

  1. Just press Alt + f + s + a

Solution 34 - Windows

If you use Total Commander there is a field in the bottom for this. It shows the active directory you are currently in and will run the entered command in that directory.

Total Commander command line

Solution 35 - Windows

Rather than saving it as a shortcut, this is how I do it and I find it very useful. There are already answers to show as a shortcut, but I just wanted to share this, especially I find it very useful for angular projects.

  • Create a new txt file and write the following code into it.
    @ECHO OFF cd C:\YourProjectPath\FolderPath\

  • save as .bat file with a convenient name. (I usually save it as "goto-myProjectName.bat"

  • Then copy that bat file into your default path (when you run the cmd, whatever is your default path, it starts with that. For instance, on my machine it is windows/system32)

  • Then type your bat file's name without its extension.

  • For instance:goto-myProjectName

Then it should take you to there.

Solution 36 - Windows

Another easy solution is to install Windows Terminal.

And then you automatically have "Open in Windows Terminal" when you right-click on a folder:

enter image description here

Solution 37 - Windows

You can also do this:

[HKEY_CLASSES_ROOT\Directory\shell\cmd]
@="command prompt here"
[HKEY_CLASSES_ROOT\Directory\shell\cmd\command]
@="cmd.exe /c start \"%1\" cmd.exe /k cd /d %1"
[HKEY_CLASSES_ROOT\Drive\shell\cmd]
@="command prompt here"
[HKEY_CLASSES_ROOT\Drive\shell\cmd\command]
@="cmd.exe /c start \"%1\" cmd.exe /k cd /d %1"

Update: for Win10 you need ShowBasedOnVelocityId - see answer above.

Solution 38 - Windows

Despite a few answers for HKCR\Directory\shell under Windows 10 (which did not work) the following worked for me:

SetOpenCmdHere.reg

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Folder\shell\cmd]
@="Open CMD here..."

[HKEY_CLASSES_ROOT\Folder\shell\cmd\command]
@="C:\\Windows\\system32\\cmd.exe /k pushd \"%1\""

Solution 39 - Windows

In windows 10, you just need one click to get cmd in any folder. Just hold "shift + mouse right click " in your desire folder and cmd will open with your folder path.

Solution 40 - Windows

Windows 10 File Explorer now has a "Quick Access Toolbar".

Just press "Alt+F" to open the file menu, navigate to the "Open Windows PowerShell" menu, right click and select "Add to Quick Access Toolbar":

enter image description here

Now you will get a little icon that you can click on, that will open PowerShell in the directory you are in: enter image description here

Solution 41 - Windows

Why that much of setup, for this simple matter, when your on the path in cmd just enter

start .

and press Enter

Solution 42 - Windows

For a better experience using a terminal in windows system, cmder may help for a shortcut usage:

  1. Download cmder into your system
  2. Make shortcut
  3. type path_of_the_cmder /START target_path_wish_to_run

For an instance:

TARGET -> C:\Users\<username>i\AppData\Roaming\cmder\Cmder.exe /START C:\SOURCE\

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHaim BenderView Question on Stackoverflow
Solution 1 - WindowsAllain LalondeView Answer on Stackoverflow
Solution 2 - WindowsMichael RatanapinthaView Answer on Stackoverflow
Solution 3 - Windowssan1deep2set3hiView Answer on Stackoverflow
Solution 4 - WindowsDon ChakkappanView Answer on Stackoverflow
Solution 5 - WindowsdF.View Answer on Stackoverflow
Solution 6 - WindowsdesmatiView Answer on Stackoverflow
Solution 7 - WindowsJason PunyonView Answer on Stackoverflow
Solution 8 - WindowsGuillermoView Answer on Stackoverflow
Solution 9 - WindowsVinayView Answer on Stackoverflow
Solution 10 - WindowsTiagoLrView Answer on Stackoverflow
Solution 11 - WindowsArman FatahiView Answer on Stackoverflow
Solution 12 - WindowssimonView Answer on Stackoverflow
Solution 13 - WindowsAbhishek ShresthaView Answer on Stackoverflow
Solution 14 - WindowsSyed. AView Answer on Stackoverflow
Solution 15 - WindowsCodismView Answer on Stackoverflow
Solution 16 - WindowsravenView Answer on Stackoverflow
Solution 17 - WindowsFocusedWolfView Answer on Stackoverflow
Solution 18 - WindowsMendi BarelView Answer on Stackoverflow
Solution 19 - WindowsTomCatView Answer on Stackoverflow
Solution 20 - WindowsQuantum DreamerView Answer on Stackoverflow
Solution 21 - Windowsofir_aghaiView Answer on Stackoverflow
Solution 22 - WindowsSrinivas PView Answer on Stackoverflow
Solution 23 - WindowsPankaj ShrivastavaView Answer on Stackoverflow
Solution 24 - WindowsJasonXAView Answer on Stackoverflow
Solution 25 - WindowsvidyView Answer on Stackoverflow
Solution 26 - WindowsPetr NovotnyView Answer on Stackoverflow
Solution 27 - WindowsView Answer on Stackoverflow
Solution 28 - Windowsdestroyer313View Answer on Stackoverflow
Solution 29 - WindowsjhasseView Answer on Stackoverflow
Solution 30 - WindowsEdward GavilánView Answer on Stackoverflow
Solution 31 - WindowsForest JackdawView Answer on Stackoverflow
Solution 32 - WindowsAlex TView Answer on Stackoverflow
Solution 33 - WindowsJulien JmView Answer on Stackoverflow
Solution 34 - WindowstotymedliView Answer on Stackoverflow
Solution 35 - WindowscuriousBoyView Answer on Stackoverflow
Solution 36 - WindowstherealcainView Answer on Stackoverflow
Solution 37 - WindowscrowdyView Answer on Stackoverflow
Solution 38 - WindowsGerold BroserView Answer on Stackoverflow
Solution 39 - WindowsNiraj ShakyaView Answer on Stackoverflow
Solution 40 - WindowsCraigoView Answer on Stackoverflow
Solution 41 - WindowsU.AView Answer on Stackoverflow
Solution 42 - WindowscagcakView Answer on Stackoverflow