void XLFileUtil::rotate(const std::string & inDir,const std::string& filenameprefix , unsigned int limit) { //ファイルを見つけてリストに入れる std::vector<rotateSt> filelist; XLFileUtil::findfile(inDir , [&](const std::string& filename,const std::string& fullfilename) -> bool { if ( strstr(filename.c_str() , filenameprefix.c_str() ) ) { filelist.push_back(rotateSt(getfiletime(fullfilename),fullfilename)); } return true; }); //limit 以上だったら、古いものから消す if (filelist.size() < limit) { return ; } //古いものを見つけるためにソートする std::sort(filelist.begin() , filelist.end() , [](const rotateSt& a,const rotateSt& b){ return a.time < b.time ; }); //リストの前の方から消していく int delCount = filelist.size() - limit; for(auto it = filelist.begin() ; it != filelist.end() ; ++it ) { XLFileUtil::del(it->fullfilename); delCount --; if (delCount <= 0) break; } return ; }
int main() { printf("In getSystemBootTime\n"); char var[48]; FILE *fp = NULL; struct tm tm; time_t t; struct timeval tv; #define CMD "date -d @$(sed -n '/^btime /s///p' /proc/stat)" memset(var,0,48); fp = popen(CMD, "r"); while (fgets(var, sizeof(var), fp) != NULL) { printf("%s", var); } pclose(fp); strptime(var, "%A %b %d %H:%M:%S %Z %Y", &tm); t = mktime(&tm); tv.tv_sec = t; tv.tv_usec = 0; printf("######################### %llu\n",getfiletime(&tv)); return 0; }
void FileInformation::getFileInformation() { QFileInfo info(fileName); fileSize=info.size(); QStringList list = fileName.split("."); fileType = list[1]; fileName = fileName.right(fileName.size() - fileName.lastIndexOf('/') - 1); fileTime = getfiletime(); }
static int count_new_mail(void *buf, int count, void *args) { struct fileheader *fp = buf; mail_count_t *cp = args; time_t date = getfiletime(fp); if (date < cp->limit) return QUIT; if (!(fp->accessed[0] & FILE_READ)) cp->count++; return 0; }