/**
* @brief onClearLogFile 清理日志目录
* @param path 目录
* @param keepLogDays 保留最近天数
*/
void onClearLogFile(QString path, int keepLogDays)
{
QStringList fileList;
//需要清理文件的类型
QStringList filterList;
QString fileType = "*.txt";
filterList.append(fileType);
//获取目录内的文件列表
QDir dir = QDir(path);
Q_ASSERT(dir.exists());
fileList = dir.entryList(filterList, QDir::Files, QDir::Name);
QDateTime currDt = QDateTime::currentDateTime();
foreach (QString fileName, fileList)
{
//获取文件的创建时间
QFileInfo info(path + "/" + fileName);
QDateTime dt = info.created();
int days = dt.daysTo(currDt);
if(days > keepLogDays)
{
QFile::remove(path + "/" + fileName);
}
}
}