alrashedf
alrashedf

Reputation: 215

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

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.

Upvotes: 6

Views: 6773

Answers (2)

dicroce
dicroce

Reputation: 46820

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

Upvotes: 1

CesarB
CesarB

Reputation: 45585

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

Upvotes: 4

Related Questions