AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Create new folder in Explorer like Win7 shortcut

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
enkidu



Joined: 05 Apr 2005
Posts: 2

PostPosted: Mon Mar 08, 2010 1:20 pm    Post subject: Create new folder in Explorer like Win7 shortcut Reply with quote

I really liked Windows7 shortcut Ctrl+Shift+n to create a new folder within the Windows Explorer. To port this feature back to former Windows versions, I simply wrote the following easy script which you are welcome to reuse.

Room for improvement:
1. I prefer to use the same ahk on all of my machines with the various Windows versions. So, how to create a "if (WinXP or WinVista)" around the code?
2. Using three times "#IfWinActive AHK_CLASS XXXXWClass" is quite unhandy. Can this be condensed elegantly?

Code:

;;;   Create new folder in explorer like Win7-Shortcut Ctrl+Shift+n 
;;;   ENGLISH OS. To adapt for other language versions, change the chars
;;;   used in the SendKeys command!!! 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Ctrl+Shift + n    -->  create new folder
#IfWinActive AHK_CLASS ExploreWClass
^+n::   
  Gosub, CreateNewFolderWithinExplorer
  return
#IfWinActive
#IfWinActive ahk_class CabinetWClass
^+n::   
  Gosub, CreateNewFolderWithinExplorer
  return
#IfWinActive
#IfWinActive ahk_class Progman
^+n::   
  Gosub, CreateNewFolderWithinExplorer
  return
#IfWinActive
CreateNewFolderWithinExplorer:
{
  KeyWait Control 
  KeyWait Alt
  KeyWait Shift
  BlockInput On
  Send {ALTDOWN}f{ALTUP}wf           ;File menu - New - Folder
  BlockInput Off
  return
}
Back to top
View user's profile Send private message
fragman



Joined: 13 Oct 2009
Posts: 1193

PostPosted: Mon Mar 08, 2010 6:45 pm    Post subject: Reply with quote

There's a built in variable for the OS, search the docs for "variables and expressions" or similar title, can't remember the name from my head.
You can use #IfWinActive for more than one hotkey, just remove the #IfWinActive's between the hotkeys.
Back to top
View user's profile Send private message
Guest






PostPosted: Mon Mar 08, 2010 7:19 pm    Post subject: Re: Create new folder in Explorer like Win7 shortcut Reply with quote

Not tested...

Code:
;;;//   Create new folder in explorer like Win7-Shortcut Ctrl+Shift+n 
;;;//   ENGLISH OS. To adapt for other language versions, change the chars
;;;//   used in the SendKeys command!!! 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

GroupAdd, ExplorerWindows, ahk_class ExploreWClass
GroupAdd, ExplorerWindows, ahk_class CabinetWClass
GroupAdd, ExplorerWindows, ahk_class Progman

;//Ctrl+Shift + n    -->  create new folder
#IfWinActive ahk_group ExplorerWindows
^+n::Gosub, CreateNewFolderWithinExplorer
#IfWinActive

CreateNewFolderWithinExplorer:
KeyWait, Control 
KeyWait, Alt
KeyWait, Shift
BlockInput, On
Send {Alt down}f{Alt up}wf           ;//File menu - New - Folder
BlockInput, Off
return
Back to top
fragman



Joined: 13 Oct 2009
Posts: 1193

PostPosted: Mon Mar 08, 2010 7:48 pm    Post subject: Reply with quote

Looks fine, but why the extra label?
Back to top
View user's profile Send private message
Guest






PostPosted: Mon Mar 08, 2010 10:50 pm    Post subject: Reply with quote

what extra label?...there is only 1...
Back to top
None



Joined: 28 Nov 2009
Posts: 3086

PostPosted: Mon Mar 08, 2010 10:59 pm    Post subject: Reply with quote

fragman means that now that you don't have three Hotkeys doing the same thing, GoSub is not needed.
Code:
GroupAdd, ExplorerWindows, ahk_class ExploreWClass
GroupAdd, ExplorerWindows, ahk_class CabinetWClass
GroupAdd, ExplorerWindows, ahk_class Progman

;//Ctrl+Shift + n    -->  create new folder
#IfWinActive ahk_group ExplorerWindows
^+n::
KeyWait, Control 
KeyWait, Alt
KeyWait, Shift
BlockInput, On
Send {Alt down}f{Alt up}wf           ;//File menu - New - Folder
BlockInput, Off
return
#IfWinActive
Back to top
View user's profile Send private message
Guest






PostPosted: Mon Mar 08, 2010 11:10 pm    Post subject: Reply with quote

I still prefer Hotkeys by themself at the top of the script...cleaner, easier to see & edit the Hotkeys...(& the Guests are not enkidu)...
Back to top
waveform



Joined: 23 Apr 2007
Posts: 21

PostPosted: Mon Aug 23, 2010 4:11 am    Post subject: Reply with quote

Just for variation, here's one I've been using which, instead of doing a File > New > Folder in the menu, uses a dialog to ask for the folder name. After creating it, it puts the cursor focus on the new folder.

Bit redundant perhaps but thought I'd post it anyway.
It relies on "Display full path in the title bar", so of course doesn't work in "My Documents" etc.

Code:
#IfWinActive ahk_class CabinetWClass
{

^+n::
  WinGetActiveTitle, Title
  IfInString Title, :\
  {
    StringRight s, Title, 1
    If s <> \
      Title := Title . "\"
    InputBox, FolderName, Create New Folder, Name of new folder:,
    If StrLen(FolderName) > 0
    {
      FileCreateDir %Title%%FolderName%
      Sleep 100
      SendInput {f5}
      Sleep 200
      SendInput %FolderName%
    }
  }
  Return


I think I'll change to using the File menu, seems more sensible. Smile
Back to top
View user's profile Send private message
fragman



Joined: 13 Oct 2009
Posts: 1193

PostPosted: Mon Aug 23, 2010 4:16 pm    Post subject: Reply with quote

Check my program 7plus to see how it's done there. I acquire a string for new folder by looking through various windows resource files, and then use COM to query explorer path, select file etc Smile
Back to top
View user's profile Send private message
dc
Guest





PostPosted: Wed Feb 16, 2011 3:45 am    Post subject: win 7 create directory Reply with quote

I have the following code that I used happily in XP, but for some reason it will not work in win7. It creates a new directory with the current date as the directory name.

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
datestr = FormatTime(YYYYMMDD)
#z::

#IfWinActive, ahk_class CabinetWClass
#z::
#IfWinActive, ahk_class ExploreWClass
#z::
#IfWinActive
; Get handle of current window, ie. Explorer one
explorerHwnd := WinExist("A")
ControlGetText currentPath, Edit1, ahk_id %explorerHwnd%


Inputbox,Descr,Direcory Description
FormatTime, TimeString, , yy-MM-dd

FileCreateDir %currentPath%\%TimeString%-%Descr%
return

If you remove the \ between the %\% it will create a directory, but only where the script resides.
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group