Windows – How to Open Command Prompt in Current Folder with Keyboard Shortcut

autohotkeycommand linekeyboard shortcutswindows

How can I open a command prompt in current folder with a keyboard shortcut in Windows 7?
Is there any way to implement this?
I think Autohotkey could do this, but don't know how.

Best Answer

Use this keyboard shortcut: Shift + Menu, W, Enter

  1. Shift + Menu (alternatively, Shift + F10), (opens extended right-click menu in current folder)

  2. W (selects "Open Command Window Here"),

  3. Enter (activates selection; required since "New" is also selectable with W)

The Menu key refers to the special key introduced by Microsoft, usually to the right of the right Win key.

This shortcut is available on a default installation of Windows (7) without any 3rd party software.


The AHK way. You just need to press Win + C (or whatever you want to define it as.):

SetTitleMatchMode RegEx
return

; Stuff to do when Windows Explorer is open
;
#IfWinActive ahk_class ExploreWClass|CabinetWClass

    ; create new text file
    ;
    #t::Send !fwt

    ; open 'cmd' in the current directory
    ;
    #c::
        OpenCmdInCurrent()
    return
#IfWinActive


; Opens the command shell 'cmd' in the directory browsed in Explorer.
; Note: expecting to be run when the active window is Explorer.
;
OpenCmdInCurrent()
{
    ; This is required to get the full path of the file from the address bar
    WinGetText, full_path, A

    ; Split on newline (`n)
    StringSplit, word_array, full_path, `n

    ; Find and take the element from the array that contains address
    Loop, %word_array0%
    {
        IfInString, word_array%A_Index%, Address
        {
            full_path := word_array%A_Index%
            break
        }
    }  

    ; strip to bare address
    full_path := RegExReplace(full_path, "^Address: ", "")

    ; Just in case - remove all carriage returns (`r)
    StringReplace, full_path, full_path, `r, , all


    IfInString full_path, \
    {
        Run,  cmd /K cd /D "%full_path%"
    }
    else
    {
        Run, cmd /K cd /D "C:\ "
    }
}

As a bonus, the script above also creates a new text file with this shortcut: Win + T

Credit to: Eli Bendersky

Related Question