Windows Explorer renames files when copying and an existing file is found - do we have access to that facility from Delphi code?
It would be fairly straight forward to write the code to rename the destination filename when using TFile.Copy(), but it would be better to use the existing code if available.
IFileOperation is the API to the shell's file copy functionality. Use it to replicate the shell's behaviour. In your case you will need to use SetOperationFlags to specify the FOF_RENAMEONCOLLISION flag:
Give the item being operated on a new name in a move, copy, or rename operation if an item with the target name already exists.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With