Using VS to develop C + + projects, it is often found that after modifying the system time, each compilation process becomes very slow, because when you move the system time to a future point in time, and then intentionally or unintentionally edit some code files, then the timestamp of these files will stay in the future.
When you set the system time to the present, the compiler will always be determined that the files are up-to-date, so the files are always compiled once, if some of these files are referenced by other files, then there will be more files are recompiled, and this process every time
Compilation is performed once, resulting in slower compilation. To solve this problem, I have written a small tool.
The principle of this tool is simple, find files in the specified directory with timestamps greater than the current time, and set their timestamps to the present time.
Call, with a bat script, you need to check the code directory to pass in, such as
Echo if resetfiletime msgdefine Server Pause
#include <io.h>#include<windows.h>#include<stdint.h>#include<vector>#include<string>#include<Set>#include<stdio.h>#include<iostream>BOOLIscompilefile (ConstSTD::string&extension) { StaticSTD::Set<STD::string> setcompliefileextension = {". cpp",". C",". CC",". h",". HPP"}; returnSetcompliefileextension.find (extension)! =setcompliefileextension.end ();} STD::stringGetfilenameextension (ConstSTD::string&fileName) { /*DWORD dwattrib = GetFileAttributes (Filename.c_str ()); if (Dwattrib = = invalid_file_attributes) {return ""; } if (Dwattrib & file_attribute_directory) {return ""; }*/size_t Dotpos= Filename.find_last_of ("."); if(Dotpos = = std::string:: NPOs) { returnFileName; } returnFilename.substr (Dotpos, Filename.length ()-dotpos);}BOOLComparesystemtime (ConstSYSTEMTIME & LHS,ConstSYSTEMTIME &RHS) { if(Lhs.wyear >rhs.wyear) {return true; } Else if(Lhs.wyear = = Rhs.wyear && lhs.wmonth >rhs.wmonth) {return true; } Else if(Lhs.wyear = = Rhs.wyear && Lhs.wmonth = = Rhs.wmonth && lhs.wday >rhs.wday) {return true; } Else if(Lhs.wyear = = Rhs.wyear && Lhs.wmonth = = Rhs.wmonth && Lhs.wday = =Rhs.wday&& lhs.whour >rhs.whour) {return true; } Else if(Lhs.wyear = = Rhs.wyear && Lhs.wmonth = = Rhs.wmonth && Lhs.wday = =Rhs.wday&& Lhs.whour = = Rhs.whour && lhs.wminute >rhs.wminute) {return true; } Else if(Lhs.wyear = = Rhs.wyear && Lhs.wmonth = = Rhs.wmonth && Lhs.wday = =Rhs.wday&& Lhs.whour = = Rhs.whour && Lhs.wminute = = Rhs.wminute && lhs.wsecond >rhs.wsecond) {return true; } Else if(Lhs.wyear = = Rhs.wyear && Lhs.wmonth = = Rhs.wmonth && Lhs.wday = =Rhs.wday&& Lhs.whour = = Rhs.whour && lhs.wminute = rhs.wminute && lhs.wsecond = Rhs.wsecond && L Hs.wmilliseconds >rhs.wmilliseconds) {return true; } return false;}voidDumpsystemtime (ConstSTD::string& Prefix,ConstSYSTEMTIME &t) {printf ("%s%04d-%02d-%02d%02d:%02d:%02d\n", Prefix.c_str (), T.wyear, T.wmonth, T.wday, T.whour, T.wminute, T.wsecond);}voidResetfiletime (ConstSTD::string&dir) {Win32_find_data fileInfo; HANDLE hfile=nullptr; CharTmppath[max_path] = {0 }; sprintf_s (Tmppath,"%s\\*.*", Dir.c_str ()); if(hfile = FindFirstFile (Tmppath, &fileinfo)) = = HANDLE (-1)) { return; } Do { if(Fileinfo.dwfileattributes &_a_subdir) { if(strcmp (Fileinfo.cfilename,".") ==0|| strcmp (Fileinfo.cfilename,"..") ==0) { Continue; } sprintf_s (Tmppath,"%s\\%s", Dir.c_str (), fileinfo.cfilename); Resetfiletime (Tmppath); } Else{sprintf_s (Tmppath,"%s\\%s", Dir.c_str (), fileinfo.cfilename); STD::stringExtension =getfilenameextension (fileinfo.cfilename); if(iscompilefile (extension)) {FILETIME lastwritelocalfiletime; FileTimeToLocalFileTime (&fileinfo.ftlastwritetime, &lastwritelocalfiletime); SYSTEMTIME Lastwritelocalsystime, Nowtime; FileTimeToSystemTime (&lastwritelocalfiletime, &lastwritelocalsystime); Getlocaltime (&nowtime); if(Comparesystemtime (Lastwritelocalsystime, Nowtime)) {HANDLE file=:: CreateFile (Tmppath, Generic_read | Generic_write, File_share_read |file_share_write, NULL, open_existing, NULL, or NULL); Dumpsystemtime (Fileinfo.cfilename, lastwritelocalsystime); FILETIME Nowwritelocalfiletime; SystemTimeToFileTime (&nowtime, &nowwritelocalfiletime); FILETIME Nowwritesysfiletime; LocalFileTimeToFileTime (&nowwritelocalfiletime, &nowwritesysfiletime); BOOL ret= Setfiletime (file, &nowwritesysfiletime, &nowwritesysfiletime, &nowwritesysfiletime); if(ret = =TRUE) {printf ("Reset Time succ.\n"); } Else{printf ("Reset Time fail.error=%d\n", GetLastError ()); } } } } } while(FindNextFile (hfile, &fileinfo) = =TRUE); FindClose (hfile);} int32_t Main (int32_t argc,Char*argv[]) { for(Int32_t i =1; i < argc; ++i) {std::stringDIR =Argv[i]; Resetfiletime (dir); } return 0;}
C + + settings file last modified time