home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / SRC15B44.ZIP / PPPURGE.C < prev    next >
C/C++ Source or Header  |  1997-04-27  |  1KB  |  56 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <dos.h>
  6. #include <dir.h>
  7. #include <time.h>
  8. #include <process.h>
  9. #include <sys/stat.h>
  10. #include "version.h"
  11.  
  12. #pragma warn -par
  13.  
  14. void main(int argc, char *argv[])
  15. {
  16.   char s[121], buf[MAXPATH];
  17.   int f1, howmany = 0, kbytes = 0;
  18.   unsigned int KEEPSENT = 99;
  19.   long age;
  20.   struct ffblk ff;
  21.   struct stat fileinfo;
  22.  
  23.   fprintf(stderr, "\n\nPPP Sent Packet Purger %s", VERSION);
  24.   fprintf(stderr, "\nContact Frank Reid at edare@abs.net or 1@8213.WWIVnet for support\n");
  25.  
  26.  
  27.   if (!argv[1])  {
  28.     printf("\n ■ Run PPPurge <days> to delete packets older than <days>.\n\n ");
  29.     exit(0);
  30.   }
  31.  
  32.   KEEPSENT = atoi(argv[1]);
  33.  
  34.   printf("\n ■ Purging sent packets older than %d days.", KEEPSENT);
  35.  
  36.   getcwd(buf,MAXPATH);
  37.  
  38.   sprintf(s, "%s\\SENT\\*.*",buf);
  39.   f1 = findfirst(s, &ff, 0);
  40.   while (f1 == 0) {
  41.     sprintf(s, "%s\\SENT\\%s",buf, ff.ff_name);
  42.     if (stat(s, &fileinfo) == 0) {
  43.       age = (time(NULL) - fileinfo.st_atime);
  44.       if (age > (86400L * (KEEPSENT+1))) {
  45.         kbytes += fileinfo.st_size/1024;
  46.         ++howmany;
  47.         unlink(s);
  48.       }
  49.     }
  50.     f1 = findnext(&ff);
  51.   }
  52.   printf("\n ■ Deleted %dKB in %d files.\n\n", kbytes, howmany);
  53.   exit(0);
  54. }
  55.  
  56.