0
我使用boost ::文件系統重新命名一個像這樣的文件:的Windows:文件重命名和目錄迭代衝突
boost::filesystem::rename(tmpFileName, targetFile);
tmpFileName /的TargetFile是一個類型爲boost :: filsystem ::路徑。
雖然這樣做,我遍歷在另一個線程使用該代碼的目錄:
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
是否有可能迭代和重命名操作衝突,因爲它們都訪問目錄inode,或者我還有其他問題?