Copy & rename (overwrite not allowed)

I need to clone/rename a set of preview JPGs whose names embed an image database’s unique record ID as part of copying the database records. An issue is that as the parent d/b records are copied they pick up a new ID in the new d/b. I can embed the old ID and thus have the new ID know that (old) p01.jpg must become p563.jpg in the new location. However, AS’ duplicate (feature) syntax doesn’t seem to allow me to set a new name for the copy, but rather I must dupe, then rename. The problem here is I can’t be sure the source’s filename isn’t already used in the target location - what happens if p01.jpg already exists in the target location as I must write the file there before I can rename it to the desired p563.jpg. I can’t rename before I copy for exactly the same name clash reason. I’m used to scripting (on other OSs) where a copy/move allows the resulting filename to be set (and altered as part of the command. Must I copy to an interim folder, rename there and then move the result to the intended target folder, or am I missing something?

TIA

Mark

You can use the shell “cp” command, something like this .

set sourcePath to POSIX path of (path to desktop)
set targetPath to sourcePath & "target folder/"

set sourceFile to "p01.jpg"
set targetFile to "p563.jpg"

set sourceFilePath to quoted form of (sourcePath & sourceFile)
set targetFilePath to quoted form of (targetPath & targetFile)

do shell script "cp " & sourceFilePath & " " & targetFilePath

Thanks. That seems to work. As there may possibly be 000,000s of records/previews to process and copy I guess there’s scope for failure occurring due to other processes interfering during the copying. Does the shell script give an error I can trap that would indicate if the copy failed for any reason?

(Lest anyone comment, this overall process may not be fast via AS or shell script but for large data sets it’s probably faster than regenerating previews from scratch!)