清理日志
void checkLogsDir()
{
QDir dir("logs"); //创建一个dir对象
if (QDir().exists ("logs"))
{
QString dateDir=QDateTime::currentDateTime ().toString ("yyyyMMdd");
QDate currentDate=QDate::fromString (dateDir,"yyyyMMdd");
// List directories that match the filters.
dir.setFilter (QDir::Dirs);
QFileInfoList dirInfoList=dir.entryInfoList ();
{
QDir dir("logs"); //创建一个dir对象
if (QDir().exists ("logs"))
{
QString dateDir=QDateTime::currentDateTime ().toString ("yyyyMMdd");
QDate currentDate=QDate::fromString (dateDir,"yyyyMMdd");
// List directories that match the filters.
dir.setFilter (QDir::Dirs);
QFileInfoList dirInfoList=dir.entryInfoList ();
int count=dirInfoList.count ();
//获取清理时间
uint intervalTime=settingValue ("clearLogsTime","interval",10,"common.ini").toUInt ()*24*60*60;
//获取清理时间
uint intervalTime=settingValue ("clearLogsTime","interval",10,"common.ini").toUInt ()*24*60*60;
for (int i=0; i<count; i++)
{ //文件信息
QFileInfo fileInfo=dirInfoList[i];
{ //文件信息
QFileInfo fileInfo=dirInfoList[i];
QString logsDirName=fileInfo.fileName (); //获取文件夹名称
if (logsDirName.length () < 8)
{
continue;
}
QDate lastDate=QDate::fromString (logsDirName,"yyyyMMdd");
if (QDateTime(currentDate).toTime_t () - QDateTime(lastDate).toTime_t () >= intervalTime)
{
QString cmd="rm -rf logs/"+logsDirName; //命令
::system (cmd.toStdString ().c_str ()); //执行命令
}
}
}
}
if (logsDirName.length () < 8)
{
continue;
}
QDate lastDate=QDate::fromString (logsDirName,"yyyyMMdd");
if (QDateTime(currentDate).toTime_t () - QDateTime(lastDate).toTime_t () >= intervalTime)
{
QString cmd="rm -rf logs/"+logsDirName; //命令
::system (cmd.toStdString ().c_str ()); //执行命令
}
}
}
}