7

I am tired of these steps when copying and renaming a file (Windows Explorer):

  1. CTRL+C
  2. CTRL+V
  3. Navigation keys
  4. F2

screenclip showing the renaming

Is there no feature or shortcut in Windows that a file gets copied and is in rename-mode immediately?

Maybe this is a sophisticated question, but doing this 50 times per day would save at least 50 * 2 keyboard strokes.

PS: I know you can do it using the CMD copy "file1.txt" "file2.txt", but I'd like to do it directly in Windows Explorer.

3 Answers 3

3
 ; Press F1 in Explorer to copy and manually rename the copy of the selected file
 ; - If the size of the selected is less 50 MB, directly in the explorer
 ; - otherwise using an input box (because the copying process takes more time) 

#If WinActive("ahk_class CabinetWClass")

    $F1::
    ClipSaved := ClipboardAll 
    clipboard := "" 
    Send, ^c 
    ClipWait, 2
    if (!ErrorLevel)
    {
        SplitPath, clipboard,, dir, ext, NameNoExt
        If (ext = "")
        {
            MsgBox, No file selected
            clipboard := ClipSaved
            return
        }
        FileGetSize, size, %clipboard%, M
        If (size < 50)
        {
            Sleep, 100
            Send, ^v
            Sleep, 500
            ; Send, {F2} ; or
            SendInput, {F2}%NameNoExt% ; if you want to remove " - Copy"
        }
        else
        {
           InputBox, UserInput, Filename, Enter a name for the file,, 350, 120,,,,, %NameNoExt%
            if (!ErrorLevel)    
                FileCopy, %clipboard%, %dir%\%UserInput%.%ext%, 1  
        }
    }
    else
        MsgBox, No file selected
    Sleep, 300
    clipboard := ClipSaved
    return

#If
4
  • Close to the finish line! Only thing left: After hitting F1, it has the copied file with - Copy in the end. test.txt becomes test - Copy.txt, but the copied file should have the same name: test.txt - Is that possible?
    – Avatar
    Jul 25, 2018 at 11:32
  • Try the edited answer.
    – Relax
    Jul 25, 2018 at 12:38
  • Perfect! That's the solution.
    – Avatar
    Jul 25, 2018 at 13:47
  • This works perfectly on Windows 7. Thank you! Jul 13, 2019 at 17:29
2

I think your best path is writing some script that does what you want, then put it in the registry so that it appears when you right click -> open with on the file. The script would take your file as a parameter and then copy and rename as you wish (especially if you only want to rename as in the example, with number suffix).

And if you're looking for keyboard only, you can place a shortcut to your script on the desktop, and in the shortcut properties assign it a keyboard shortcut.

If you need to give a specific name to the file (i.e. not just an auto-suffix) you can always pop an input box of your own from the script - it's easy in most languages.

Bottom line, if you can code it, it can be done... If not, it could be a good context to take your first coding steps!

0

This does exactly what you want.

  1. Install AutoHotkey from Here.
  2. Create file with .ahk extension and paste the code below into it.
  3. Double click on it to run.
  4. Select the file you want to copy and rename.
  5. Press Ctrl+Alt+A to apply.

^!a:: ; Press [ Control + Alt + A ].
    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)
            CurrentWindow := window.Document.SelectedItems
            for item in CurrentWindow 
            {
                CopyNumber := 1
                Selectedfile := ""
                Selectedfile := item.path
                SplitPath, % Selectedfile,name, dir, ext, name_no_ext
                Loop
                {
                    if FileExist( dir "\" name_no_ext "-" CopyNumber "." ext )
                        CopyNumber += 1
                    else 
                    {
                        FileCopy, % Selectedfile, %dir%\%name_no_ext%-%CopyNumber%.%ext%
                        Break
                    }
                }
            }
        }
Return
2
  • @G-Man Says 'Reinstate Monica', Hey how you could edit my post?, that is nice! thank you.
    – Smile
    May 10, 2020 at 1:12
  • Anybody can suggest an edit to other people’s posts.  At first your suggested edit has to be reviewed and approved by other people.  When you reach 2000 reputation points, you can skip the review and just do the edit;  see the Help Center. May 10, 2020 at 1:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .