; In some cases, Windows automatically re-selects the entire file name when renaming a file via F2.
; I have searched for how to disable this behavior and have not found a solution. This script uses
; InputBox as a work-around. It works on renaming multiple files as well. If anyone knows the real
; registry that fixes the problem, please do reply here.
F2::Explorer_RenameSelectedFile()
Explorer_RenameSelectedFile() {
MouseGetPos, rnx, rny
ControlGetPos, cx, cy
ControlGetFocus, thisControl, A
if (thisControl != "DirectUIHWND3") {
exit
}
Menu, Tray, Icon, imageres.dll, 204
file_name := Explorer_ReturnFileName()
InputBox, new_name, Rename File, , , 250, 100, %cx%, %cy%,,,%file_name%
if (ErrorLevel) {
Menu, Tray, Icon, autotext.ico
Exit
} else {
SendInput {F2}
SendInput %new_name%
SendInput {Enter}
}
Menu, Tray, Icon, autotext.ico
}
Explorer_GetSelection(hwnd="") {
hwnd := hwnd ? hwnd : WinExist("A")
WinGetClass class, ahk_id %hwnd%
if (class="CabinetWClass" or class="ExploreWClass" or class="Progman")
for window in ComObjCreate("Shell.Application").Windows
if (window.hwnd==hwnd)
sel := window.Document.SelectedItems
for item in sel
ToReturn .= item.path "`n"
return Trim(ToReturn,"`n")
}
Explorer_ReturnFileName(hwnd="") {
file_path := Explorer_GetSelection(hwnd)
SplitPath, file_path, , , , file_name
return file_name
}
InputBox to rename selected file in Explorer (avoids annoying Windows autoselect)
- Delta Pythagorean
- Posts: 627
- Joined: 13 Feb 2017, 13:44
- Location: Somewhere in the US
- Contact:
Re: InputBox to rename selected file in Explorer (avoids annoying Windows autoselect)
Psst, use the
Code: Select all
blocks!
[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat
Re: InputBox to rename selected file in Explorer (avoids annoying Windows autoselect)
Yeah, I was really tired when I put that up. Now that I know posts cannot be deleted (this was my first submission), and after finding a dozen problems (I didn't test it), I think it in my best interest for that up there to remain incomprehensible until I come up with something that doesn’t make me feel like I drunk dialed my friends mom but cannot remember which friend it was...
Return to “Scripts and Functions (v1)”
Who is online
Users browsing this forum: No registered users and 135 guests