AutoHotkey Community

It is currently May 27th, 2012, 4:41 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: March 8th, 2010, 2:20 pm 
Offline

Joined: April 5th, 2005, 4:54 pm
Posts: 2
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
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 8th, 2010, 7:45 pm 
Offline

Joined: October 13th, 2009, 10:09 pm
Posts: 1389
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.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 8th, 2010, 8:19 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 8th, 2010, 8:48 pm 
Offline

Joined: October 13th, 2009, 10:09 pm
Posts: 1389
Looks fine, but why the extra label?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 8th, 2010, 11:50 pm 
what extra label?...there is only 1...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 8th, 2010, 11:59 pm 
Offline

Joined: November 28th, 2009, 4:45 am
Posts: 3089
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 9th, 2010, 12:10 am 
I still prefer Hotkeys by themself at the top of the script...cleaner, easier to see & edit the Hotkeys...(& the Guests are not enkidu)...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 23rd, 2010, 5:11 am 
Offline

Joined: April 23rd, 2007, 10:21 pm
Posts: 21
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. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 23rd, 2010, 5:16 pm 
Offline

Joined: October 13th, 2009, 10:09 pm
Posts: 1389
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 :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject: win 7 create directory
PostPosted: February 16th, 2011, 4:45 am 
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.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 16 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group