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?
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.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
try to unlink() it. It should work.
Windows doesn't allow you to delete a file that's already open. Try this: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; }
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.