Automatic rename file

Hi all,
I want to create a button that will automatically rename a group of select files, adding a number with leading zeros if a file already exists.

for example:
suppose i have this list of files in my folder:

aaa.txt
bbb.txt
bbb01.txt

and i select aaa.txt and bbb.txt i would like a command that will rename them to aaa01.txt and bbb02.txt

so the result would be:
aaa01.txt <--- used to be aaa.txt
bbb01.txt
bbb02.txt <--- used to be bbb01.txt

I tried looking for an answer but couldn't find one that suits my need. :confused:
thanks fot help!

the result should be:
aaa01.txt <--- used to be aaa.txt
bbb01.txt
bbb02.txt <--- used to be bbb.txt

thanks!

You can create a button to do this if you want, but I'd just use the standard built in renaming tool to do it like the screen shot below indicates.

Note if you also have file bbb01.txt selected, it too, will be renamed to bbb03.txt as shown below. So if you don't want that one changed, don't select it.

i'm using now the renaming tool (just like you suggested) but because i use this function quite often in my work, i was wondering what is the way to make this function work as a button/hotkey/context menu command.
thanks again.

Ah, ok. Try using this as a button command then:

Rename NUMBER 01

how could i miss that?!? :laughing:
i tested it, and it's almost what i need. the problem is that when i select aaa01.txt and run the command, it won't rename it :confused: any idea how to make it work?

I don't understand, what should aaa01.txt be renamed to? The rename command attempts to rename all selected files by ending the existing file names with incrementing numbers (starting with 01). So aaa01.txt wouldn't be renamed as it would be the same name.

If you want to change the button so it will prompt you for a starting number to append, you might give something this a try:

Rename NUMBER {dlgstring|Enter first number|01} AUTORENAME

I should also mention the rename command starts with 01 (or whatever starting number you use) and applies that to whatever the top selected file name is. In other words, if you reverse sort by name, with aaa01.txt being the third file selected, then aaa01.txt will be renamed to aaa03.txt

i guess i wasn't clear enough.
i sometimes have files which ends with a number, for example: aaa1.txt ot aaa01.txt, i'm trying to rename them also with a click of a button.

maybe i will explain what i'm trying to do. i have a folder (let's call it A) with a list of files, from time to time, i need to copy files to that folder from another location (let's call it :sunglasses:, and i need to keep the existing files, but with a different name.

for example, i have those files in folder A:
aaa.txt
bbb.txt
ccc123.txt
ddd.txt

now i need to copy aaa.txt, bbb.txt, ccc123.txt from another folder B to this location. so what i'm doing (manually) is first renaming in A aaa.txt --> aaa_01.txt, bbb.txt --> bbb_01.txt, ccc123.txt --> ccc123_01.txt, and i copy the files from B to A.

after couple of minutes i need to copy aaa.txt from another folder B to this location A. so what i'm doing now (again, manually) is renaming aaa.txt --> aaa_02.txt (because aaa_01.txt already exists) and then i copy aaa.txt from B to A

the final result is that i have in A:
aaa.txt
aaa_01.txt
aaa_02.txt
bbb.txt
bbb_01.txt
ccc123.txt
ccc123_01.txt
ddd.txt

the original files can have any name possible, some of them are even ending with a number, for example ccc123.txt or ccc01.txt, it's confusing i know, but i can't control their names.

hope you can help me now, and i really appriciate your efforts, this forum rocks.

Well my first thought was to wonder why you can't simply copy from folder B to folder A using the autorename option which automatically resolves naming conflicts. But I guess you need aaa.txt to be the newest version of the file and it also needs to remain named aaa.txt while older versions of aaa.txt are renamed with incrementing numbers?

It sounds to me like we're getting close to scripting land for off the top of my head I don't know of a way to do exactly that from within Opus without a script. However if you're willing to be a bit adventurous, you could try this providing you're using Windows 2000 or newer. Create a basic text file with only the following in it and save it as c:\test.bat

@rem BEGIN BATCH FILE @echo off

set SRC=%~1
set DST=%~2

if exist "%DST%%~nx3" (
dopusrt /cmd rename "%DST%%~nx3" NUMBER 01 AUTORENAME
)

dopusrt /cmd copy file %3
rem END BATCH FILE

Then set up a standard (meaning not an MSDOS Batch) function Opus button with the following command:

C:\test.bat {s} {d} {f}

To run the button/script first set up your source and destination listers, then click your desired source files to be copied, and press the button you just made. If all goes well, any preexisting aaa.txt files should be autorenamed using a combination of incrementing numbers and the autorename option. Then the new aaa.txt file should be copied to the destination retaining it's original name. This isn't quite what you wanted, but I don't see an uncomplicated way to do it exactly as you wish without using the autorename option.

Thanks, you are the best, i'm sure i can take it from here. :exclamation: :opusicon:

Here's my solution to this... what is yours?

[code]@rem BEGIN BATCH FILE
@echo off

set SRC=%~1
set DST=%~2
set FN=%3

REM //For Debugging purposes only
REM echo %SRC% %DST% %3
REM echo "%DST%%~nx3"
REM pause

if exist "%DST%%~nx3" (
echo "Renaming existing file in destination"
rename "%DST%%~nx3" "%~n3 Original%~x3"
)
echo "Copying new file to destination"
copy %3 "%DST%%~nx3"
REM //Can use move instead as well
REM move %3 "%DST%%~nx3"
pause
rem END BATCH FILE

REM //===NOTES===
REM // %~dpI - expands %I to a drive letter and path only
REM // %~nxI - expands %I to a file name and extension only
REM // %~nI - expands %I to a file name only
REM // %~xI - expands %I to a file extension only
REM // %~I - expands %I removing any surrounding quotes (")
REM // %1 - First passed parameter and so on...
[/code]

I often do this to preserve the original file contents, and i used only DOS commands and ignored DOPUS...

but did create a button the same way

C:\RenameOriginal.bat {s} {d} {f}

is there a better way? like an option to create a backup if overwriting files? maybe dopus has this?[/code]