home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / TODAYBAK.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  2KB  |  96 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  TODAYBAK.C - Back up today's work to a specified floppy
  5. **
  6. **  public domain demo by Bob Stout
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <dos.h>
  13. #include "sniptype.h"
  14. #include "cast.h"
  15. #include "dirport.h"
  16.  
  17. #if defined(__ZTC__) && (__ZTC__ < 0x600)
  18.  #define _dos_getdate   dos_getdate
  19.  #define _dos_setdate   dos_setdate
  20.  #define _dosdate_t     dos_date_t
  21. #endif
  22. #ifdef __TURBOC__
  23.  #define _dosdate_t     dosdate_t
  24. #endif
  25.  
  26. struct DOS_DATE {
  27.         unsigned int da : 5;
  28.         unsigned int mo : 4;
  29.         unsigned int yr : 7;
  30.         } ;
  31.  
  32. struct _dosdate_t today;
  33. struct DOS_DATE   ftoday;
  34. char   drive;
  35.  
  36. void do_dir(char *);
  37. void usage(void);
  38.  
  39. int main(int argc, char *argv[])
  40. {
  41.       int i;
  42.  
  43.       _dos_getdate(&today);
  44.       ftoday.da = today.day;
  45.       ftoday.mo = today.month;
  46.       ftoday.yr = today.year - 1980;
  47.  
  48.       if (2 > argc)
  49.             usage();
  50.  
  51.       drive = *argv[1];
  52.       if (!strchr("AaBb", drive))
  53.             usage();
  54.  
  55.       if (3 > argc)
  56.             do_dir(".");
  57.       else for (i = 2; i < argc; ++i)
  58.             do_dir(argv[i]);
  59.  
  60.       return EXIT_SUCCESS;
  61. }
  62.  
  63. void usage(void)
  64. {
  65.       puts("usage: TODAYBAK floppy [dir1] [...dirN]");
  66.       puts("       Copies today's files to the specified floppy.");
  67.       puts("       floppy = 'A' | 'B'");
  68.       puts("       with no directories specified, "
  69.             "uses current directory");
  70.       exit(EXIT_FAILURE);
  71. }
  72.  
  73. void do_dir(char *path)
  74. {
  75.       char search[67];
  76.       DOSFileData ff;
  77.  
  78.       strcat(strcpy(search, path), "\\*.*");
  79.       if (Success_ == FIND_FIRST(search, 0xff, &ff)) do
  80.       {
  81.             if (!(ff_attr(&ff) & _A_SUBDIR) && '.' != *(ff_name(&ff)))
  82.             {
  83.                   if (CAST(unsigned short, ff_date(&ff)) ==
  84.                         CAST(unsigned short, ftoday))
  85.                   {
  86.                         char cmd[128];
  87.  
  88.                         sprintf(cmd, "COPY %s\\%s %c: > NUL",
  89.                               path, ff_name(&ff), drive);
  90.                         system(cmd);
  91.                   }
  92.             }
  93.       } while (Success_ == FIND_NEXT(&ff));
  94.       FIND_END(&ff);
  95. }
  96.