Delete file in Delphi use

Asked

Viewed 881 times

0

Does anyone know if it is possible to delete a file on Delphi, using the function DeleteFile, when the file is open?

Thanks in advance.

  • The process that gets locked the ". eml" the name of the running . exe is different from your application, if yes, could call the CMD command taskkill /f /im ProcessoEml.exe and then end the process and then create the file again.. what do you think ?

1 answer

-1

There is no way, you would need to do via source code at the event onDestroy of Form for it to change the name, assume the new changed file and delete the old one, this to executable. For text files it manages to delete the file even with it opened, if try to save it saved in the same place it was deleted.

  • Good afternoon Jrudolf. I am trying to delete a ". eml" file, which is open. I have a routine where you save this file and open it. If the user does not close it and click on generate the email again, when saving it I receive the message that it already exists and if I try to delete it does not delete and continues there. Thanks in advance.

  • 1

    You could do a routine to force the process to end, if the user generates the file again with it opened, you can check if it is open and give a message.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.