Mimic Vista's File Rename Feature in XP
Posted by Adam Pash at 1:00 PM on February 13, 2008
Dear Lifehacker,
The only Vista feature (honestly) I hoped that XP could have is a very simple one. In Explorer if you hit F2 to rename a file Vista automatically selects the file name WITHOUT the extension, something that does not happen in XP. I cannot begin to describe how frustrating it is to hit F2+Shift+<-<-<-<- every time I need to rename a file. Can you help me?
Respectfully,
Renaming Randy
Dear Randy,
I'm all over this one, and it's AutoHotkey to the rescue!
It's very possible that there are better ways to add this functionality, but it's wildly easy to do with AutoHotkey, so that's what I've done. Like you said, every time you hit F2 to rename a file, you also need to hit Shift+Left Arrow four times. Using AutoHotkey, I've just automated that process.
If you're just interested in getting the functionality, either download the Better Rename.exe file or download the AutoHotkey source. If you want a better idea of how it works, check out the code below:
AnalyzeRename:
OldClipboard = %Clipboard%
sleep 100
Send, ^c
StringGetPos,ExtensionPos, Clipboard,.,R
if (ExtensionPos != -1)
{
Position := StrLen(Clipboard) - ExtensionPos
Send, +{Left %Position%}
}
Clipboard = %OldClipboard%
return
Now let's dissect it. The IfWinActive command tells AutoHotkey only to use these F2 definitions if your active Window or application is Windows Explorer or your Desktop. If either of those conditions are met, F2 is sent to the window, and then AutoHotkey automates the Shift+Left keystrokes necessary to un-highlight the extension, but it does so quickly enough that it's really as though that's just the way renaming works.
This was a very quickly thrown together script, and there are limitations that could be improved. I did add checking for the first period from the right so that F2 can handle extensions of differing lengths and so that it doesn't try adjusting the selection for items that don't use extensions—folders, for example.
It's not absolutely perfect, but it should do the trick most of the time if you've been aching from the renaming functionality that's available in both Vista and OS X.
Love,
Lifehacker
P.S. Interested in more of what AutoHotkey can do? Check out this introduction or any of our many AutoHotkey posts.
Tags: autohotkey | autohotkey answers | downloads | exclusive lifehacker download | how to | lifehacker code | top | vista | windows | windows tip | windows xp

Comments (AU Comments · US Comments)
There are currently no AU comments for this post.
Gina Trapani
Posted 1:44 PM 13/2/08
@aaron8301: Calling people names is a good way to get yourself banned from commenting here.
Gina Trapani
aaron8301
Posted 1:44 PM 13/2/08
Randy, you're an idiot. "Hide extensions for known file types." Plain and simple. Unless you're dealing with a lot of files that aren't registered on your computer, but then, why the hell would you be doing that?
aaron8301
InspectorxGadget
Posted 1:44 PM 13/2/08
I'm going to have to go against the grain and say that I don't like the fact that Vista defaults to only editing the information before the extension. I would prefer it to work the other way so re-naming Winamp skins, .nfo files, etc. could be done with fewer keystrokes.
InspectorxGadget
jarmod
Posted 1:44 PM 13/2/08
If AHK is a registered file extension and you have "Hide extensions for known file types" enabled (the default) then renaming a file on XP is quite safe.
jarmod
Brimstone
Posted 1:44 PM 13/2/08
My favorite file manager, xplorer2, has this feature built-in.:)
Brimstone
Midget Man
Posted 2:49 PM 13/2/08
You lifehacker have just got some major brownie points for this, I rename files after I download them and categorize it in one of my many folders, and I always hated having to unselect the Extension that it uses,
@AARON830
and the whole problem with the Hiding the Extensions is that you can't really change the OS to what you want or know exactly whats on your computer.
And thanks again Lifehacker.
Midget Man
frank26080115
Posted 2:49 PM 13/2/08
It didn't work for me so I modified it, way simpler approach:
#IfWinActive ahk_class CabinetWClass
~F2::
Gosub, AnalyzeRename
return
#IfWinActive ahk_class Progman
~F2::
Gosub, AnalyzeRename
return
#IfWinActive
AnalyzeRename:
Send, {left}
Send, {left}
Send, {left}
Send, {left}
Send, +{home}
frank26080115
chris-mcc
Posted 2:49 PM 13/2/08
I hate this feature in Vista. I'm always having to rename extensions and it's annoying that they aren't selected by default.
chris-mcc
frank26080115
Posted 2:49 PM 13/2/08
It doesn't work!
I'm serious, it just moves the cursor to the left, nothing is selected.
frank26080115
Panhandler
Posted 2:49 PM 13/2/08
Hey neat, F2 lets you rename files easily!
/not all of us know even the basic tricks. (:
Panhandler
jeffk
Posted 2:49 PM 13/2/08
AARON830, you're an [not considering all users' wishes]!
I find it difficult to navigate if I can't see extensions.
And I like the Vista feature.
jeffk
Venki
Posted 2:49 PM 13/2/08
Another option is to use QTTabbar [qttabbar.wikidot.com], which has this feature. I have been using it quite a while after reading about it in LH. Though its not like xplorer2, it has those Vista explorer features built in for XP.
Venki
BrianW62
Posted 2:49 PM 13/2/08
@echostats: Only if you have "Show all file extensions" disabled in the Finder preferences. Otherwise you have the same problems with renaming and extensions that you have with XP.
Hiding file extensions is just asking for trouble, IMO. I want to know exactly what I'm clicking on.
BrianW62
ACF
Posted 2:49 PM 13/2/08
@above
Besides, UN-hiding extensions is one of the first things an adept computer user does so that they have more knowledge and control of their computer.
It is also a security issue, as the safe_picture.jpg(.exe) your aunt can really mess things up. See: [blog.washingtonpost.com] and [www.cert.org] <-- more in depth
ACF
echostats
Posted 2:49 PM 13/2/08
Vista feature? OS X has been doing this for awhileeeeee...
echostats
jackmc
Posted 3:49 PM 13/2/08
Gnome (ie Linux) has it too :)
You could also hide extensions if you don't need them/if they are more trouble than they are worth...
jackmc
thirdopticaltool
Posted 3:49 PM 13/2/08
I never thought about this until it was built into OS X 10.5 as the default... Now i can't imagine living without it. :)
thirdopticaltool
tap52384
Posted 5:04 PM 13/2/08
The QTTabBar would be the best bet, as F2 functionality is not restricted to just file renaming, just in case you have some other program that uses that key. QTTabBar now comes with the ability to hide the menu bar in Explorer, which is great.
tap52384
darsal
Posted 5:04 PM 13/2/08
I'm totally guessing, but wouldn't the send-send-send-send or send 4 combo only work for three letter extensions? With a shorter extension you'd skip selecting part of the filename, and with a longer extension you'd get no "." or maybe even mangle the extension. (If you notice immediately, CTRL+Z would fix it.)
darsal
yitzle
Posted 5:04 PM 13/2/08
@chris-mcc: You can just reverse the hack and have it automatically select the extension in Vista.
yitzle
turnersd
Posted 5:04 PM 13/2/08
I upgraded back to XP recently and this is the only single thing I did miss about vista. I think LH should ask the readers to share their favorite AHK tricks in the comments sometime.
By the way, Here is the same thing in one line of code:
~F2::Send +{left 4}
You lose your f2 key but if it's that important, remap it to something else such as another useless F-key or the scroll lock perhaps, like this:
F4::
Send {F2}
Send +{left 4}
return
turnersd
800hightech
Posted 6:05 PM 13/2/08
Great tip! Its not like I didn't know how to go about doing this, it just never occured to me!
I always set up hotkeys for editing applications to save time and my finger muscles, never though about it for xp.....Thanks
800hightech
gifo
Posted 6:05 PM 13/2/08
Notes:
1. On my XP machine the ahk_class for File Explorer is ExploreWClass, not CabinetWClass. I guess it'd be safer to add both classes in a general-issue script.
2. Performance is inconsistent. Sometimes it works, sometimes not. Maybe it has to do with the 100 mS delay, but I didn't test it comprehensively.
gifo
ddyment
Posted 6:05 PM 13/2/08
[b]My[/b] favourite file manager, FreeCommander, displays two separate fields in its file rename GUI, so you can rename the file, or change its extension, independently.
ddyment
Smizler
Posted 8:09 PM 13/2/08
I'd like to add that if you have QTtabar installed this performs the same result.
Smizler
Crescent
Posted 9:12 PM 13/2/08
Well Randy, if u r the kind o person who believes this will increase his productivity, ..... dude u don`t need to increase it, it won`t matter to the world, or anybody including you. I do this all the time, f2 is wonderful as it is, I love changing file extensions, but then I am not bound by microsoft as I am guessing u r.
by the way, pressing left arrow 4 times takes 1 second... lame randy, really lame, 4 1 second... lame
Crescent
JimmyCane
Posted 9:12 PM 13/2/08
and my favorite Filemanager UltraExplorer has this feature also build in! A single press of F2 to just select the name, another time F2 to also select the extension.
greetings
JimmyCane
Johnay
Posted 4:28 PM 16/2/08
F2, huh? I've always just done a slow double-click, then selected whatever I want to change with the mouse.
I just tried it, and if you happen to have two functional hands you can hit F2 then quickly select whatever part of the name you want with a deft sweep of the mouse.
Johnay
CaptainRoin
Posted 4:28 PM 16/2/08
Pitaschio does this, and works great!
There are tons of other cool features as well.
CaptainRoin
j3sX
Posted 4:28 PM 16/2/08
@chris-mcc:
Firefox + Greasemonkey + Lifehacker Nested Comments = Problem solved.
j3sX
vandasian
Posted 4:28 PM 16/2/08
This tip is what will make me try out AutoHotkey I think. I rename so many files....One question, does this work in save file dialog boxes?
Finally, I'll add my HO to the rest here that if you don't have "Hide extensions for known file types" turned off you are not a power user.
vandasian
OzTardis
Posted 4:28 PM 16/2/08
@JimmyCane: Actually, for me the following happens when you repeatedly hit F2 in Win Explorer:
1 - name+ext selected
2 - nil selected (cursor to home ready to add name prefix)
3 - name selected
4 - nil selected (cursor to end of filename before . ready to add name suffix)
5 - ext selected
6 - name+ext selected (ie cycle back to 1)
Sorta logical in a way. So you'd achieve the same thing by hitting F2 3 times. And yes, it works as expected if you have multiple extensions (.jpg.exe) or ext other than 3 chars.
But yes, I was going to suggest QTTabBar or Pitaschio as it's just one of many many improvements, but others beat me to it... YMMV as I tested above with QT installed but have that feature disabled.
OzTardis
royalcow
Posted 4:28 PM 16/2/08
Couldn't you use the WinGetText function to grab the highlighted text rather than the clipboard. Here is another version of AnalyzeRename:
-----------------
AnalyzeRename:
WinGetText,filename
lastelement:=SubStr(filename,(Instr(filename,"FolderView")+12),-1)
StringGetPos,ExtensionPos,lastelement,.,R1
ExtensionPosRight:=strlen(lastelement)-ExtensionPos-1
Send, +{Left %ExtensionPosRight%}
return
----------------
Basically it gets the highlighted text, does some parsing and then moves the cursor.
royalcow
nitemer100
Posted 4:28 PM 16/2/08
I have to give another shout out to xplorer2, I use the free version and have been for a long time now. Once you learn how to take advantage of it's features you will never go back to Windows Explorer. You can just do the simple things so much faster.
Hitting F2 will highlight the filename without extension. If you hit Control-F2 you can edit the entire filename.
nitemer100
foxmajik
Posted 4:28 PM 16/2/08
Double click the first part of the file name.
foxmajik
chris-mcc
Posted 4:28 PM 16/2/08
I really wish Lifehacker's comment system had some sort of threading system. Theres about 20 different conversations about this topic and it's hard to sort though them when they're flat like this.
Thanks to whoever suggested trying this script on Vista and reversing it to have the old XP way of file rename selection. I don't use AutoHotkey for anything else so I'm not sure if it's worth it for this one hack but maybe I'll look into it.
chris-mcc
brianary
Posted 4:28 PM 16/2/08
Just so we're clear: GNOME had it before Vista. I don't know if GNOME was first, though.
brianary
JDW
Posted 4:28 PM 16/2/08
Randy,
Take a look at Pitaschio (mentioned at [lifehacker.com]), it will give you what you need. The setting to check in the main configuration window is "Allow extended filename". This selects the text of the filename excluding the extension.
Pitaschio also has a number of other very useful tweaks you won't find in one package.
PS Yes the spelling is PITASCHIO.
Cheers,
~JDW
JDW
HeartBurnKid
Posted 4:28 PM 16/2/08
@Crescent: Now, where did I read something about removing the beam from your own eye before criticizing the mote in your neighbor's?
Anyway, I really dig the script, and I'll probably put it into my own system. I'd like to see the functionality extended a bit, in order to include the other methods of renaming that don't necessarily involve F2, but I'm not really sure if that's possible under AutoHotKey, so I'll leave it alone for now. Thanks, Adam, and thank you for asking for it, Randy!
HeartBurnKid
Crescent
Posted 4:28 PM 16/2/08
@TasteTheFlava: I type all day, change file names a few times max in a day, I use all the shortcuts when writing, cause simply, my fingers hurt.
I hope u get my point.
Cheers
Crescent
TasteTheFlava
Posted 4:28 PM 16/2/08
Back on topic, I actually didn't know that F2 renamed files either. Always find good tips on Lifehacker!
TasteTheFlava
TasteTheFlava
Posted 4:28 PM 16/2/08
@Crescent: Well Crescent, if you're the type of person who believes only typing 'u' instead of 'you', or 'r' instead of 'are', or '4' instead of 'for' will increase his productivity... dude.
By the way typing 'you' takes 1 second... lame Crescent, really lame.
TasteTheFlava
GTD Wannabe
Posted 4:28 PM 16/2/08
I found this feature invaluable when using X2, but I don't use it *all* the time. So, when using Explorer, I kept getting frustrated. Thanks LH for making my day. You rock!
GTD Wannabe
Djago1
Posted 4:28 PM 16/2/08
When I first saw this posted here, I was excited about having this excellent feature on XP. This script, however, sucks badly. It only moves four spaces, as opposed to finding the last used . in the name and going just before it, so if a file has more than 3 letters in the extension (e.g. .html) then it doesn't work.
Sorry to say that this fails.
Djago1
jermainePropane
Posted 4:28 PM 16/2/08
Note that the code in the article didn't work with a direct copy and paste into notepad. I had to manually go in and break the lines between the top bits of code, because they all pasted in as one long string (on only one line.)
"#IfWinActive ahk_class CabinetWClass ~F2:: Gosub, AnalyzeRename return #IfWinActive ahk_class Progman ~F2:: Gosub, AnalyzeRename return #IfWinActive"
jermainePropane
fedmich
Posted 4:28 PM 16/2/08
I installed QT Tab bar (Enhances explorer) and it's one of the feature of this tab bar. I suggest that you install it, Google it up :)
But I actually hate this behavior, Id rather it dont automatically hilite it for me, I rarely Not change file ext when renaming...
Cheers to all
fedmich
cr0ft
Posted 4:28 PM 16/2/08
This is a very minor thing but it is in xplorer2 - and xplorer2 is worth its price many times over for a multitude of reasons including this one.
Or else just go to Zabkat.com and grab the free version, even that is a huge productivity enhancer when moving and renaming or indeed any file management work.
cr0ft
photoben
Posted 4:28 PM 16/2/08
@ACF: It is SOO much easier when you can see the extensions. I really don't know what Aaron is going on about.
photoben
boandmichele
Posted 4:28 PM 16/2/08
in Gnome, this is available by default. however, it doesnt lock you from changing the extension if you want, it just automatically highlights the file name. i think this is the best way to do it.
minor inconsistencies like this is why i stopped using windows in the first place. i think its great that fixes are coming out that give users the functionality they want in either XP or vista. (microsoft should support xp longer)
boandmichele
bobbo33
Posted 4:28 PM 16/2/08
This tip is only a productivity enhancement if you change file names a lot. If you change extensions a lot, it's the opposite of helpful. But if you're like me, sometimes it's the names, sometimes it's the extensions - just depends on my current task.
So I created an Autohotkey script that toggles the "hide file extensions" on/off by pressing CTRL+F2... The best of both worlds!
-----------------------------------------------------
^F2::GoSub,CheckActiveWindow
CheckActiveWindow:
ID := WinExist("A")
WinGetClass,Class, ahk_id %ID%
WClasses := "CabinetWClass ExploreWClass"
IfInString, WClasses, %Class%
GoSub, Toggle_HideFileExt
Return
Toggle_HideFileExt:
RootKey = HKEY_CURRENT_USER
SubKey = Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced
RegRead, HideFileExt_Status, % RootKey, % SubKey, HideFileExt
if HideFileExt_Status = 1
RegWrite, REG_DWORD, % RootKey, % SubKey, HideFileExt, 0
else
RegWrite, REG_DWORD, % RootKey, % SubKey, HideFileExt, 1
PostMessage, 0x111, 41504,,, ahk_id %ID%
PostMessage, 0x111, 28931,,, ahk_id %ID%
Return
bobbo33
bougatsa
Posted 4:28 PM 16/2/08
Wow, I've never seen so much hostility towards the OP on here before. Since when did LH become the Consumerist?!
Anyway, here's another vote for Xplorer2.
To me, an OS is just a tool for running apps and switching between them, and Vista/XP/OS X all do this perfectly well. So file management becomes the make-or-break feature for an OS. (Vista is fine overall, but I would have 'upgraded' to XP if Xplorer2 was not compatible with Vista).
IMO:
Xplorer2 >> XP Explorer >> Vista Explorer and OS X Finder tie for last very different reasons.
bougatsa
masmarius
Posted 4:28 PM 16/2/08
Pitaschio has this feature built in ;)
masmarius
ogabriel
Posted 4:28 PM 16/2/08
Not working for me(i´ve also make my very own copying the scripts from the comments)
I´m using windos XP brazilian portugues. can anyone help?
ogabriel
tomxp
Posted 4:28 PM 16/2/08
Along the same lines, I download files regularly that come in this format: xxxx021308_xxxxxxx.ext
What I want to do is to simply omit the leading and trailing garbage, keep the date, and then enter a descriptive name after the date. As an AHK novice, I can easily get to the point where I can enter the new name, but I'd really like to PAUSE there, be prompted to enter the new name, and then have the program continue on to the next file on the list. Surely this is duck soup for you proficient gurus!
tomxp
ranimi
Posted 4:28 PM 16/2/08
I'm a fan of QTTabBar which integrates this functionality. Give it a try!
ranimi
vicu9mx
Posted 4:28 PM 16/2/08
I use QtTabs at work and my home, sadly in my home computer with XP x64 that feature doesn't work :(
vicu9mx
jreedar
Posted 4:28 PM 16/2/08
I really like this but it didn't work in explorer for me on XP Pro, I checked and my active window name using the Window Spy utility built into AHK and it was named 'ExploreWClass' so I commented out the line that used 'CabinetWClass' and added a line with 'ExploreWClass', works perfectly now.
;#IfWinActive ahk_class CabinetWClass
#IfWinActive ahk_class ExploreWClass
jreedar
bsr35802
Posted 3:16 PM 18/2/08
@Johnay: We aren't trying to be lazy and saying it is too much work. But it is more productive to combine your two-handed process with a single keystroke. The concept described here may apply to many more examples.
bsr35802
jermainePropane
Posted 3:44 AM 19/2/08
here is a pasteable version of the article code. textsnip.com/874ea8
jermainePropane
prattmic
Posted 11:14 AM 24/2/08
@royalcow: That works well, however it doesn't work on folders, so I altered the code a bit.
AnalyzeRename:
WinGetText,filename
lastelement:=SubStr(filename,(Instr(filename,"FolderView")+12),-1)
StringGetPos,ExtensionPos,lastelement,.,R1
ExtensionPosRight:=strlen(lastelement)-ExtensionPos-1
if ExtensionPos != -1
{
Send, +{Left %ExtensionPosRight%}
}
return
prattmic