Thanks to @Karan for the AutoHotkey idea in the comment to the question.
The following script gets the filename from the currently selected file in Explorer, shows a message box to enter the new name and then creates a copy of the file. I haven't tested what happens if you select multiple files. Adapt to your needs:
#Requires AutoHotkey v2.0-
#Warn
#SingleInstance
#HotIf WinActive("ahk_exe explorer.exe")
^q::DuplicateFile(GetSelectedFilePaths())
GetSelectedFilePaths() {
winClass := WinGetClass( "ahk_id" . hWnd := WinExist("A"))
if (winClass ~= "Progman|WorkerW|(Cabinet|Explore)WClass") {
shellWindows := ComObject("Shell.Application").Windows
if (winClass ~= "Progman|WorkerW")
shellFolderView := shellWindows.Item( ComObject(VT_UI4 := 0x13, SWC_DESKTOP := 0x8) ).Document
else {
for window in shellWindows
if (hWnd = window.HWND) && (shellFolderView := window.Document)
break
}
result := ""
for item in shellFolderView.SelectedItems
result .= (result = "" ? "" : "`n") . item.Path
if !result
result := shellFolderView.Folder.Self.Path
} else {
ClipSave := ClipboardAll
Clipboard := ""
SendInput "^c"
ClipWait 2
result := Clipboard
Clipboard := ClipSave
}
Return result
}
DuplicateFile(Source, Overwrite := false) {
SplitPath Source, &name, &dir, &ext, &name_no_ext, &drive
IB := InputBox("Please enter the new name:", "Duplicate file", "w200 h80", name_no_ext)
if IB.Result = "OK"
FileCopy Source, dir "\" IB.Value "." ext, Overwrite
}
I got the code for the explorer script from the AutoHotkey forum, but adapted it to v2.
While this hasn't been the question, also notice that it is possible to change the default rename template (i.e. the "- Copy"), editing HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\NamingTemplates\CopyNameTemplate
(String) in the registry. The default is %s - Copy
, where %s
is the old name. This is described here.