1

How do I make F1 be a hotkey in Windows XP assigned to creating a new folder?

I don't know too much about programming or scripting. Can AutoHotkey do this?

  • Where is the new folder to be located? – martineau Nov 4 '11 at 14:45
  • Hi Martin, I think the new folder should be created in the same folder/desktop that I am browsering. – grandproducts Nov 4 '11 at 15:21
5

Yup. Use FileCreateDir.

windowText =
line =
path =
name =

$F1::                                                   ;the $ locks the keystroke so you don't get Windows Help
    IfWinNotActive, ahk_class CabinetWClass
        Return                                          ;If the active window is not an explorer window, do nothing
    WinGetText, windowText, ahk_class CabinetWClass,    ;get text info
    StringSplit, line, windowText, `n                   ;take the first line of windowText this will be "Address: path"
    StringReplace, path, line1, Address: `              ;trim off Address: 
    StringTrimRight, path, path, 1                      ;trim off new line character at the end
    InputBox, name, MakeDirF1, Enter the name of the new folder.    ;get a name
    If name == ""                                       ;if name is blank
        name := "New Folder"                            ;then set name
    FileCreateDir, %path%\%name%                        ;create the folder
    If ErrorLevel == 1                                  ;check for errors
        MsgBox, Error!`n`n%A_LastError%                 ;message box if error
    Return
  • Thanks, Ampersand, it really works! Though there seem to be a little problem creating new folder just on the Desktop – grandproducts Nov 7 '11 at 12:38
  • Hmm... sorry for the late reply. It would work if you navigated to the desktop in an Explorer window. Otherwise, you can just map a key to send the requisite keystrokes. $F1:: { Click, Right Send, wf RETURN } – Ampersand Nov 18 '11 at 17:40
  • @Ampersand: Seems like you could detect when the desktop is active by looking for an active window of ahk_class Progman and then automatically create a subfolder in the user's desktop folder if that's the case. Also, at least on my XP SP3 system, Explorer windows have a ahk_class ExploreWClass, not CabinetWClass. – martineau Mar 4 '12 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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