tri this
/*
Gary Russell
ghrussel@swbell.net
ISSW
Deletes all files in the current directory over 14 days old.
*/
#include <conio.h>
#include <io.h>
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#include <dir.h>
//---------------------------------------------------------------------------
//Get the day of the year.
int get_yday(char s, int day, int mo) {
int add, yday;
if(mo == 1) { add = 0; }
if(mo == 2) { add = 31; }
if(mo == 3) { add = 59; }
if(mo == 4) { add = 90; }
if(mo == 5) { add = 120; }
if(mo == 6) { add = 151; }
if(mo == 7) { add = 181; }
if(mo == 8) { add = 212; }
if(mo == 9) { add = 243; }
if(mo == 10) { add = 273; }
if(mo == 11) { add = 304; }
if(mo == 12) { add = 334; }
if(s != 'f' && mo == 12 && day == 17) { }
yday = add + day;
return yday;
}
//---------------------------------------------------------------------------
int main() {
int fday, sday, done;
char type, end[] = "*.*";
FILE *fp;
std::ftime ft;
struct date d;
struct ffblk ffblk;
done = findfirst(end, &ffblk, 0);
while (!done) {
if((fp = fopen(ffblk.ff_name, "rb")) == NULL) {
printf("\n\nCan not open output file!\n"); getch(); exit(1); }
getdate(&d);
type = 's';
sday = get_yday(type, d.da_day, d.da_mon);
getftime(fileno(fp), &ft);
fclose(fp);
type = 'f';
fday = get_yday(type, ft.ft_day, ft.ft_month);
if(sday + 13 < fday) { remove(ffblk.ff_name); }
done = findnext(&ffblk);
}
return 0;
}