c++ - Get files creation or modification time? -
i want creation or modification time of files , compare system time.
if (fileextensions[i] == restoken && lmdcheck.getcheck() == true) { testbox3.addstring(allfiles[i]); cfilestatus status; cfile cfile; //cfile.open(allfiles[i],null,null); cfile.open(allfiles[i], cfile::moderead | cfile::modewrite); ctime t = ctime::getcurrenttime(); trace(t.format(l"%x\n")); systemtime systemtime; //::getsystemtime(&systemtime); ::getlocaltime(&systemtime); ctime systemt(systemtime); trace(systemt.format(l"%x\n")); ulonglong dwnewlength = 10000; cfile.setlength(dwnewlength); if (cfile.getstatus(status)) { if (status.m_ctime < systemtime) { cfile.close(); cfile::remove(allfiles[i]); } } }
and delete file less system time. please help?
this compare file's filetime current systemtime
bool get_finddata(const tchar *filename, win32_find_data &data) { if (!filename) return false; handle h = findfirstfile(filename, &data); if (h == invalid_handle_value) return false; findclose(h); return true; } void change_filetime(filetime &ft, int sec) { ulonglong temp = (((ulonglong)ft.dwhighdatetime) << 32) + ft.dwlowdatetime; temp += sec * __int64(10000000);//100-nanosecond intervals ft.dwlowdatetime = (dword)(temp & 0xffffffff); ft.dwhighdatetime = (dword)(temp >> 32); } void checkfor_older_files(const tchar *filename) { win32_find_data finddata; if (!get_finddata(filename, finddata)) return; //finddata.ftcreationtime; //finddata.ftlastwritetime; //finddata.ftlastaccesstime; systemtime st; getsystemtime(&st); filetime comparetime; systemtimetofiletime(&st, &comparetime); //change comparetime, example, files older 30 minutes change_filetime(comparetime, -30 * 60); if (comparefiletime(&finddata.ftcreationtime, &comparetime) < 0) outputdebugstring(l"older file\n"); else outputdebugstring(l"not old\n"); }
Comments
Post a Comment