Reputation: 21194
From an application I want to delete a folder. The problem is that the folder also contains that application. So, as long as the application is running the folder is locked. How can I delete that folder?
The first thought was to make a copy of that application in 'Temp' and run it from there. This way it it will release the folder. Not a very elegant solution though....
The OS is Win7 but it should work on all from Win2K up to Win 8. The goal is to let the application to self-uninstall (clean up its folder, then self delete).
Somebody suggested that if I do this in my app it will work. It doesn't.
SetCurrentDir(SomeOtherFolder);
Upvotes: 1
Views: 235
Reputation: 613282
On Windows, the executable file is locked while the process executes in such a way that the file cannot be deleted. So you will need to wait until the process has stopped executing before you can delete the executable file.
There are two options that appear to me to be viable:
Upvotes: 2