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.
+4
A:
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).
CesarB
2008-10-18 19:20:56
Related answer: http://stackoverflow.com/questions/259253/how-do-i-copy-a-file-or-folder-that-is-locked-under-windows-programmatically#259262
CesarB
2008-11-03 16:56:55
+1
A:
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... :)
dicroce
2008-10-18 21:14:23