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

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  FLOPCOPY.C
  5. **
  6. **  Copy a floppy to a hard disk directory with directory recursion
  7. **  Public domain, uses functions from SNIPPETS.
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include "sniptype.h"
  14. #include "dirport.h"
  15. #if defined(MSDOS) || defined(__MSDOS__)
  16.  #include "unistd.h"
  17. #else
  18.  #include <unistd.h>
  19. #endif
  20. #include "snipfile.h"
  21.  
  22. void do_dir(char *, char *);
  23.  
  24. /*
  25. **  Copy a floppy to an HD subdirectory
  26. */
  27.  
  28. int main(int argc, char *argv[])
  29. {
  30.       char fdrv[4] = "A:\\", target[FILENAME_MAX];
  31.  
  32.       if (3 > argc)
  33.       {
  34.             puts("Usage: FLOPCOPY drive_letter subdir");
  35.             puts("where: drive_letter is \"A\" or \"B\" (colon optional)");
  36.             puts("       subdir is drive:dir target, e.g. \"C:\\FLOPSTUF\"");
  37.             return EXIT_FAILURE;
  38.       }
  39.       *fdrv = *argv[1];
  40.       strcpy(target, argv[2]);
  41.       if ('\\' != LAST_CHAR(target))
  42.             strcat(target, "\\");
  43.       
  44.       do_dir(fdrv, target);
  45.       return EXIT_SUCCESS;
  46. }
  47.  
  48. /*
  49. **  Process a directory (SNIPPETS: Treedir.C, modified)
  50. */
  51.  
  52. void do_dir(char *from, char *to)
  53. {
  54.       char search[FILENAME_MAX], new[FILENAME_MAX], newto[FILENAME_MAX];
  55.       DOSFileData ff;
  56.  
  57.       strcat(strcpy(search, from), "*.*");
  58.       if (Success_ == FIND_FIRST(to, _A_ANY, &ff))
  59.       {
  60.             if (0 == (ff_attr(&ff) & _A_SUBDIR))
  61.             {
  62.                   printf("*** %s Exists and is not a directory!\n", to);
  63.                   return;
  64.             }
  65.       }
  66.       else
  67.       {
  68.             strcpy(newto, to);
  69.             if ('\\' == LAST_CHAR(newto))
  70.                   LAST_CHAR(newto) = NUL;
  71.             mkdir(newto);
  72.       }
  73.       if (Success_ == FIND_FIRST(search, _A_ANY, &ff)) do
  74.       {
  75.             if (ff_attr(&ff) & _A_SUBDIR && '.' != *ff_name(&ff))
  76.             {
  77.                   strcat(strcat(strcpy(new, from), ff_name(&ff)), "\\");
  78.                   strcat(strcat(strcpy(newto, to), ff_name(&ff)), "\\");
  79.                   do_dir(new, newto);
  80.             }
  81.             else
  82.             {
  83.                   char file1[FILENAME_MAX], file2[FILENAME_MAX];
  84.  
  85.                   if ((ff_attr(&ff) & (_A_SUBDIR | _A_VOLID)) ||
  86.                         '.' == *ff_name(&ff))
  87.                   {
  88.                         continue;
  89.                   }
  90.                   strcat(strcpy(file1, from), ff_name(&ff));
  91.                   strcat(strcpy(file2, to), ff_name(&ff));
  92.                   if (Success_ != file_copy(file1, file2))
  93.                         printf("*** Unable to copy %s to %s\n", file1, file2);
  94.                   else  printf("Copied %s to %s\n", file1, file2);
  95.             }
  96.       } while (Success_ == FIND_NEXT(&ff));
  97. }
  98.