比如下面的代码,删除nDays之前的老日志,在vs2019和2022运行都没问题,但是在vs2015下,即使是nDays以内的文件,fileTime < nDaysAgo也成立,运行结果就是所有的日志都清除了
#if defined(_MSC_VER)
#if _MSC_VER == 1900
namespace fs = std::experimental::filesystem;
#elif _MSC_VER >= 1910
namespace fs = std::filesystem;
#endif
#endif
void LoggerUtil::cleanFiles(const fs::path& p, const unsigned int nDays)
{
if (!fs::exists(p) || !fs::is_directory(p))
return;
std::lock_guard<std::mutex> lock(gMtxClean);
// Get the current file time
fs::file_time_type currentTime = fs::file_time_type::clock::now();
// Calculate the file time n days ago
fs::file_time_type nDaysAgo = currentTime - std::chrono::hours(24) * nDays;
// Recursively iterate over files in the folder
//for (const auto& f : fs::recursive_directory_iterator(p)) {
for (const auto& f : fs::directory_iterator(p)) {
if (fs::is_regular_file(f)) {
// Get the last write time of the file
fs::file_time_type fileTime = fs::last_write_time(f);
// Check if the file is older than n days
if (nDays > 0 && fileTime < nDaysAgo)
dirfile_util::RemoveFile(f.path());
}
}
}
请教,什么原因造成的这种结果,是代码有问题吗?还是说filesystem在vs2015本身就是experimental不稳定的?
--
修改:miui FROM 114.252.238.*
FROM 114.252.238.*