#include <sys/stat.h>
#include <stdio.h>
#include <dirent.h>
int main()
{
DIR *dir;
struct dirent *d;
struct stat buf;
int days;
int curtime;
curtime = time(0);
dir = opendir("./");
while (d = readdir(dir)) {
if (strcmp(d->d_name, ".") == 0 ||
strcmp(d->d_name, "..") == 0)
continue;
stat(d->d_name, &buf);
days = (curtime - buf.st_atime) / 86400;
if (days > 30)
remove(d->d_name);
}
closedir(dir);
printf("Deleted all files not accessed for 30 days.\n");
return 0;
}