How do I programmatically force the deletion of files that are locked by the operating system or any other program with C/C++? The functionality should be similar to the software "Unlocker" at http://ccollomb.free.fr/unlocker.
相关问题
- Sorting 3 numbers without branching [closed]
- Multiple sockets for clients to connect to
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
This really depends on the underlying filesystem.
For example, on Linux, ext3 supports file attributes that are not part of the standard unix read/write/execute/user/group/world paradigm.
There is a nice summary of the available attributes here:
Really drove me crazy the first time I came across, and even as root, and even after rebooting off a bottable CD I still couldn't delete a file off my hard drive... BTW, the possibilities for creative use of this for practical jokes are nearly endless... :)
Look this sample.
If you are on Win32, the official way to do it is to mark it to be deleted on reboot, and ask the user to reboot. To mark the file to be deleted on reboot, use MoveFileEx with the MOVEFILE_DELAY_UNTIL_REBOOT flag (pass NULL as the destination).