Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Explorer renames files when copying and an existing file is found

Tags:

winapi

delphi

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.

like image 823
Michael Vincent Avatar asked Jan 05 '23 17:01

Michael Vincent


1 Answers

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.

like image 124
David Heffernan Avatar answered Jan 16 '23 23:01

David Heffernan