I know it can be done, somehow you have to close any handle that has that file open in other programs. The problem is HOW?
Printable View
I know it can be done, somehow you have to close any handle that has that file open in other programs. The problem is HOW?
Is this for console prog or Windows prog? o_O
You cannot force other programs to close a handle to a file. You can just try to kill them - and the user will probably kill YOU if you do that.
Of course, not all OSs prevent deletion of a file that is open. Linux (and most other *nixes, I think) let you allow any file at any time, provided you have the permissions. Unless you explicitly use a locking mechanism to lock the file.
So this thread should be moved to the Windows board.
try to unlink() it. It should work.
Windows doesn't allow you to delete a file that's already open. Try this:Quote:
DEV-C++ on WIN2000
On Windows, you can't delete a file that's already open/running.Code:#include <iostream>
#include <cstdio>
int main(int argc, char *argv[]) {
if(std::remove(argv[0])) {
std::cout << "Error deleting self" << std::endl;
}
return 0;
}