Move selected items to a new folder with AutoHotkey

There’s no shortcut for creating a new folder if you have files selected in Windows Explorer, so I made one with AutoHotkey. I always find using AHK a bit kludgy if it relies on sending keystrokes; there’s too much that can go wrong. But anyway, here ’tis.

#IfWinActive ahk_class CabinetWClass
^!n::
    moveToNewFolder()
Return
#IfWinActive

moveToNewFolder(){
Send ^x
InputBox, name, Enter Folder Name,
Sleep, 50
Send ^+n
Send %name%
Send {Enter}
Sleep, 50
Send {Enter}
Sleep, 500
Send ^v
Sleep 100
Send !{up}
}

What it does is:

  • check that the window is an Explorer window, and if it is the keystroke shift + alt + n calls the moveToNewFolder function, which:
  • cuts the selected items,
  • gets the name for the new folder,
  • sends the keystrokes for creating a new folder in explorer,
  • opens that folder,
  • pastes,
  • and goes back up one level

4 comments

  1. Thanks for the script!

    I’m new to AHK, and having troubles figuring out how to make this work in Windows 10?

    So I copied the code to a new .ahk file…now what?
    How do I select multiple files in Explorer and send to a new folder?

    Thank you…

    Reply

    1. The script has to be running. If you open the script with AHK it should start running (AHK should be the default application to open .ahk files if it’s installed correctly). Then if you hit ctrl-shift-n in an explorer window it will do its thing.

      Reply

  2. That did the trick, thanks.

    Now for my real goal…be able to use this in the ‘send to’ context menu in Explorer.

    Your thoughts on what I would need to do to make that work?

    Reply

  3. cancel-button with real function:

    #IfWinActive ahk_class CabinetWClass
    ^!n::
    moveToNewFolder()
    Return
    #IfWinActive
    moveToNewFolder()
    {
    Send ^x
    InputBox, name, Enter Folder Name,
    if ErrorLevel{

    }
    else
    {
    Sleep, 50
    Send ^+n
    Send %name%
    Send {Enter}
    Sleep, 50
    Send {Enter}
    Sleep, 500
    Send ^v
    Sleep 100
    Send !{up}
    }}
    return

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *