Archive: Deleting Fille after FileClose


Deleting Fille after FileClose
  Hi Folks,

I try to delete a file after I have read it with my NSIS installer but the file is not deleted. If the installer is still running and I try to delete the file manually I receive an error message, saying the file is still in use.

My code looks like this:

FileOpen$0 "$EXEDIR\temp\test.cfg" r

FileRead$0 $1
>...
>FileClose $0
Delete "$EXEDIR\temp\test.cfg"
After some queries I have figured out the following: If I add a "Delete $0" between FileOpen and FileClose, the installer does now delete the file:
FileOpen$0 "$EXEDIR\temp\test.cfg" r

FileRead$0 $1
>...
>Delete $0
FileClose$0
Delete "$EXEDIR\temp\test.cfg"
Can anybody explain why the file is not deleted with the first version?

You just need to use /REBOOTOK option to delete on reboot that file. Anyway I don't know the reasone of that behaviour. =P


For all, who face the same problem, the following solved the problem. I added a sleep argument after closing the file and was then able to delete it:

FileOpen$0 "$EXEDIR\temp\test.cfg" r 

FileRead$0 $1
>...
>FileClose $0
Sleep 2000
Delete "$EXEDIR\temp\test.cfg"