How can I force the deletion of locked files in C/

2020-02-11 05:25发布

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.

标签: c++ c
3条回答
我欲成王,谁敢阻挡
2楼-- · 2020-02-11 05:48

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... :)

查看更多
别忘想泡老子
3楼-- · 2020-02-11 05:54

Look this sample.

查看更多
家丑人穷心不美
4楼-- · 2020-02-11 06:03

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).

查看更多
登录 后发表回答