Renaming files when copying

I'm trying to make a rename function that would copy selected files to my apache server's directory and copy link to clipboard so that file so that I could share my files with friend easily using my server.
Everything is OK (the file(s) (eg. file.png) is copied to apt dir and link like myaddress/file.png is copied to clipboard) unless file named file.png already exists in the destination (server's) dir. Then I'm asked for the new name, file is renamed, but the link in clipboard contains the old name instead of the new name.

I would like it to copy to the clipboard the new name after renaming copied file (please note that spaces in file names are converted into %20).
rename_function.txt (1.32 KB)

Anyone can help? Or noone knows what's that all about?

You can't access the new name that Opus assigns to the file being copied as part of the "Confirm File Replace" dialog... I think the most practical way(s) you can make this work would be to:

a.) use some way of uniquely renaming the file that you can more reasonably expect to NOT have a name conflict with in the destination... For instance, if you can count on each picture you'll want to copy having a valid {shootingtime} value which Opus can access via the FILEINFO rename option, perhaps that value can help to uniquely enough rename the files before you copy them.
b.) test the destination directory inside your script, check for a name conflict and then both determine the new name for the destination file and actually perform the copy from within the script using another call with dopusrt...

There could be other ways... but those are the ones that come to mind.

Thank you, I will try to make it when I got some time.

I'll fool around with it later after work if I can as well... shout back if you've already fixed it :slight_smile:.

I made it. :smiley:
Thank you very much for your help.
There might be some problems when you copy file named "A" and there is a dir named "A" in the destination dir - script will rename it to "A0", but in the purpose of file sharing I don't bother.
rename function correct.txt (3.51 KB)

I didn't check it before, but it's appropriate behavior, you can't create a file and a dir with the same same (like file "A" and dir "A") in one directory - tested on Vista.

A Folder and a File cannot have the same name in any version of Windows, or any other file system.

The next to last line should be:

Shell.Run """" & strOpusHomePath & """ /CMD Copy File """ & strFilePath & "\" & strFileName & """ To """ & destinationDir & """ As """ & newName & """" '
"" was missing after strFilePath and caused an error when files were copied from root directory. I forgot to post it earlier.