find out which process is using the file
Quote:
How to find out which handle or DLL is using a file
Open Process Explorer, running as administrator.
Enter the keyboard shortcut Ctrl+F. Altenatively, click the “Find” menu and select “Find a Handle or DLL”.
A search dialog box will open.
Type in the name of the locked file or other file of interest.
(there are other ways of doing that - Process Explorer from SysInternals *may* help)
if it's your own process, you may need a delay between the copy and delete or some other method of flushing/forcing your process to let go of the file