Copy a file to a folder with guarantee unique name ...

Hi all,
I just started learning AppleScript and trying to copy a file to a folder but I would like not to replace an existing file with the same name in folder(if already exists one with the same name)
this behavior is like as we see with Finder to duplicate an item in folder with adding “copy n” to end of the file name.
Can some one help me how to implement this.
Thank you
Nima

Have you seen this post?

Thank, that’s work fine.
Just another question:
If i want to bring up the Copy Alert when you’re trying to copy one file to a folder when the file exists already in the folder as Finder does with showing: An item named … already exists in this location, do you want to replace it?"

Is any option available for copy or duplicate in AppleScript?

Thanks,
Nima

I’m not sure I’m following you because my script in the post I refer to never copies a file that exists so what exactly do you mean by that.

But to answer your question

You have to do it yourself.

  1. check if a file exists (there are multiple ways of doing this)
  2. if target exists give the user a prompt
  3. if the user confirmed then replace the file the way you like it (also multiple ways of doing this).

the simple finder command without prompting is

duplicate theFile to theFolder with replacing
--or when you don't want to replace 
duplicate theFile to theFolder without replacing