Title: Delete a file and wait till complete before continuing.
Question: How do I delete a file and then wait until it has gone before continuing. I need to delete something and then create a new version of it to write to.
Answer:
Using this simple function you can suspend your application until a file has actually been deleted, rather than issue the DeleteFile command and get an error message when you try to create the file again on the next line. (This is quite common when windows does not execute the delete command as quickly as your application can pass it over.)
procedure WipeFile(sFileName: String);
begin
If FileExists(sFileName) then DeleteFile(sFileName);
While FileExists(sFileName) do
Application.ProcessMessages;
end;
Very simplistic code, but if you use this instead of DeleteFile, you know that the file is gone.