boost::filesystem::rename(tmpFileName, targetFile);
在执行此操作时,我在另一个线程中使用以下代码遍历目录:
directory_iterator end_itr;
for (directory_iterator itr(dirInfoPath); itr != end_itr; ++itr)
{
path currentPath = itr->path();
if (is_directory(itr->status()))
{
// skip directories
}
else
{
std::string file_name = currentPath.leaf();
if (!boost::algorithm::starts_with(file_name, "new")
&& !boost::algorithm::starts_with(file_name, "finished")
&& boost::algorithm::ends_with(file_name, ".info"))
{
// save found filename in some variable
return true;
}
}
}
执行此代码时,重命名时出现异常:
boost::filesystem::rename: The process cannot access the file because it is being used by another process