Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there an option or tool that will allow me to change the default naming convention for files copied into the same directory in Windows (XP) and above.

e.g. from: Copy of {name}.{ext} to: {name}.{ext}.copy

Currently:

original_file.php
Copy of original_file.php

Desired:

original_file.php
original_file.php.copy

This would make finding/working with duplicated files much easier (they auto-sort together) and the filetype (by extension) changes thus it can't accidentally "break" something (e.g. if it were a *.java file, upon compiling I would get errors)

share|improve this question
    
Notepad++ Workaround: If you only deal with files containing text, as the PHP ending above implies, you could use Notepad++ with its autosave feature. See >Settings >Preferences >Tab "Backup/AutoCompletion" use "Simple backup" for only 1 backup file, use "Verbose backup" for a separate folder where files get timestamps. Also check out the plugin Autosave, this might be what you want. –  Echt Einfach TV Jun 23 at 11:08

2 Answers 2

up vote 8 down vote accepted

If I understand right, you want to create duplicates of the files in the same directory. I created a .cmd file to do this via the "Send To" menu. If a name.ext.copy file already exists, it will create:

  • name.ext.copy2
  • name.ext.copy3
  • etc...

To install

  1. Go to the Start > Run... menu and type "sendto" or "shell:sendto".
  2. In the window that pops up, create a new text file.
  3. Open the new file in Notepad.
  4. Paste in the text below.
  5. Rename the text file to "Copy of.cmd" (with the quotes).

To use

  1. Select one or a group of files.
  2. Right-click on the file(s).
  3. Select the Send To... > Copy of.cmd option.

Copy of.cmd

for %%f in (%*) do call :try_copy %%f
goto :eof

:try_copy
if not exist "%~1.copy%2" goto :copy
call :try_next %1 %2
goto :eof

:copy
copy %1 "%~1.copy%2"
goto :eof

:try_next
if "%2" == "" ( set _next=2 ) else ( set /a _next=%2 + 1 )
call :try_copy %1 %_next%
goto :eof
share|improve this answer
    
Thanks @kskfisher! that looks like it will a great workaround (should there not be a default way) to do this. ;-) –  scunliffe Mar 11 '10 at 18:16

So I've solved that:

for %%f in (%*) do call :try_copy %%f
goto :eof

:try_copy
if not exist "%~d1%~p1%~n1{copy%2}%~x1" goto :copy
call :try_next %1 %2
goto :eof
:copy
if "%2" == "" call :try_next %1 %2
copy %1 "%~d1%~p1%~n1{copy%2}%~x1"
exit

:try_next
set /a _next=%2 + 1
call :try_copy %1 %_next%
goto :eof

I would guess the path problem you posted stems from how you made the contextmenu entry, because I do not have that problem.

[HKEY_CLASSES_ROOT\*\shell]

[HKEY_CLASSES_ROOT\*\shell\AllF01]
 @="C&@py"

[HKEY_CLASSES_ROOT\*\shell\AllF01\command]
 @="C:\\AEdNs\\nCodIP\\nCodIU\\Copy.cmd \"%1\""

I do not use MS Windows Explorer. I use various portable/freeware file managers.

All (but one) had the problem that the original script would copy the file to root "install" directory of the freeware file manager, so I added %~d1%~p1 which puts the drive\path of the original file on the output file ...

I tweaked the code in various ways for various reasons and to launch the code on any selected file(s) via the XP context menu not SendTo.

share|improve this answer
    
Thanks @AEN - just wondering how you "install" this to be its own context menu item vs. a child of the send to menu? –  scunliffe Sep 14 '11 at 15:18
1  
Actually, I did manage to edit the registry and add this option to the context menu... but I think it tries to create the copy/search in the directory where my *.cmd file is, not the directory of the selected file. I used the registry settings (adjusted) from here: superuser.com/questions/65105/… to add the context item. –  scunliffe Sep 14 '11 at 15:36
    
AEN, you should register on the site, or try to keep your cookies, otherwise you won't be able to edit or answer your own post. Also, please keep it civil, what we "editors" do is – in the first place – to keep everything easy to read. As per the FAQ, the actions taken here should be clear to you. Just take it as a gentle reminder, no offense intended. –  slhck Sep 15 '11 at 10:44
    
I like your batch code. When copying a file called file.txt repeatedly using your code via the "Send To" menu, this yields file{copy1}.txt, file{copy2}.txt, and so on. However, if someone would rather yield file(1).txt, file(2).txt, and so on, the parts of your code that show {copy%2} can be changed to (%2). I know this is an old thread, but wanted to contribute for others that may come across this page. –  Trekker Sep 24 at 21:28

protected by nhinkle Sep 15 '11 at 10:22

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.