How to check if a file is open with boost
How to check if a file is open with boost, if the file does not open and then delete that file, another wise does nothing
boost::filesystem::wpath file("c://test.txt");
if(boost::filesystem::exists(file))
{
if(here i want a check that file is already open or not, if open then run else)
{
boost::filesystem::remove(file);
}
else
{
}
}
source to share
It is up to the OS to prevent / resolve this.
Each OS has its own locking methods for exclusive use, in which case uninstallation will fail anyway.
Other operating systems (POSIX) separate the file record from the inode, and the file remains available to the processes that have the file open. When the last use of the inode goes away, the file is actually deleted.
In short, don't try to detect the front, just check if the deletion failed. Otherwise you will face the specified race condition
How will you deal with situations where a file is opened between your check and your attempt to delete it? here
You seem to have missed this (after seeing your answer) and Mike explained
source to share