Windows calls the _stat function, and the Linux call is the stat function.
#include <time.h>#include<sys/types.h>#include<sys/stat.h>#include<stdio.h>#include<errno.h>intMainvoid ){ intresult; Char* filename ="Putty.exe"; //errno_t err;#ifdef WIN32struct_stat buf; Result= _stat (filename, &buf);#else structstat buf; Result= stat (filename, &buf);#endif if(Result! =0) {perror ("problem getting information" ); Switch(errno) { Caseenoent:printf ("File%s not found.\n", filename); Break; Caseeinval:printf ("Invalid parameter to _stat.\n"); Break; default: /*should never be reached.*/printf ("unexpected error in _stat.\n"); } } Else { //Output Some of the statistics:printf"File Size:%ld\n", buf.st_size); printf ("Drive :%c:\n", Buf.st_dev +'A' ); time_t T; Tzset (); /*Tzset ()*/T=Time (NULL); if((T-buf.st_mtime) >604800)//604800 is the number of seconds in 7 days, the following is the deletion of files over 7 days{remove (filename); printf ("remove file:%s \ n", filename); } }}
Cross-platform query file time, if more than 7 days, delete the file (Windows and Linxu tested)