 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
enkidu
Joined: 05 Apr 2005 Posts: 2
|
Posted: Mon Mar 08, 2010 1:20 pm Post subject: Create new folder in Explorer like Win7 shortcut |
|
|
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 |
|
 |
fragman
Joined: 13 Oct 2009 Posts: 1193
|
Posted: Mon Mar 08, 2010 6:45 pm Post subject: |
|
|
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 |
|
 |
Guest
|
Posted: Mon Mar 08, 2010 7:19 pm Post subject: Re: Create new folder in Explorer like Win7 shortcut |
|
|
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
|
Posted: Mon Mar 08, 2010 7:48 pm Post subject: |
|
|
| Looks fine, but why the extra label? |
|
| Back to top |
|
 |
Guest
|
Posted: Mon Mar 08, 2010 10:50 pm Post subject: |
|
|
| what extra label?...there is only 1... |
|
| Back to top |
|
 |
None
Joined: 28 Nov 2009 Posts: 3086
|
Posted: Mon Mar 08, 2010 10:59 pm Post subject: |
|
|
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 |
|
 |
Guest
|
Posted: Mon Mar 08, 2010 11:10 pm Post subject: |
|
|
| 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
|
Posted: Mon Aug 23, 2010 4:11 am Post subject: |
|
|
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.  |
|
| Back to top |
|
 |
fragman
Joined: 13 Oct 2009 Posts: 1193
|
Posted: Mon Aug 23, 2010 4:16 pm Post subject: |
|
|
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  |
|
| Back to top |
|
 |
dc Guest
|
Posted: Wed Feb 16, 2011 3:45 am Post subject: win 7 create directory |
|
|
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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|