crymedry
MIS
- Nov 19, 2003
- 54
what command in c can i use to check the modify date of files in different directories and delete the ones older than 30 days?
thanks for you help
thanks for you help
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
#include <stdio.h>
#include <dir.h>
#include <time.h>
#define SECSINDAY 51000
int main(void) {
struct ffblk ffblk;
int done;
int pastdate;
time_t timer;
struct tm *tblock;
int days = 30;
timer = time(NULL) - (days * SECSINDAY);
tblock = localtime(&timer);
// shift values into pastdate to give same format as ffblk.ff_fdate
pastdate = ((tblock->tm_year - 80) << 9)
+ ((tblock->tm_mon+1) << 5)
+ tblock->tm_mday;
done = findfirst("*.*",&ffblk,0);
while (!done) {
printf("%s - ",ffblk.ff_name);
if (ffblk.ff_fdate <= pastdate) {
printf("delete\n");
remove(ffblk.ff_fname);
}
else printf("keep\n");
done = findnext(&ffblk);
}
return 0;
}