home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff284.lzh / RecurDir / mydir.c < prev    next >
C/C++ Source or Header  |  1989-11-27  |  2KB  |  112 lines

  1. /****************************************
  2.   mydir.c
  3.  
  4.   By Stephen Vermeulen 1989
  5.  
  6.   (403) 282-7990
  7.  
  8.   PO Box 3295, Station B
  9.   Calgary, Alberta,
  10.   CANADA, T2M 4L8
  11.  
  12.   Placed in the public domain, do with as
  13.   you please.
  14.  
  15.   This routine is used to recursively
  16.   decend the file system tree from our
  17.   current directory location.
  18.  
  19.   It prints the full relative path (relative to the path you
  20.   supply to the CLI) to each file on a line by itself to your
  21.   CLI.  This is useful as an aid in doing recursive directory
  22.   ZOOing.  For example to zoo the complete contents of DF0: you
  23.   can do:
  24.  
  25.     mydir df0: | zoo aI completedisk
  26.  
  27.   and if you don't have pipes you can use:
  28.  
  29.     mydir >temp df0:
  30.     zoo <temp aI completedisk
  31. *****************************************/
  32.  
  33. #include <stdio.h>
  34. #include <libraries/dos.h>
  35. #include <workbench/workbench.h>
  36. #include <functions.h>
  37. #include <stdio.h>
  38.  
  39. ScanDir(lock, dirname)
  40. ULONG lock;
  41. char *dirname;
  42. {
  43.   ULONG tlock;
  44.   char tdir[256], t;
  45.   struct FileInfoBlock *fib;
  46.  
  47.   fib = (struct FileInfoBlock *) AllocMem((long) sizeof(struct FileInfoBlock), 0L);
  48.   if (fib)
  49.   {
  50.     if (Examine(lock, fib))
  51.     {
  52.       while (ExNext(lock, fib))
  53.       {
  54.         strcpy(tdir, dirname);
  55.         if (strlen(tdir))
  56.         {
  57.           t = tdir[strlen(tdir) - 1];
  58.           if ((t != '/') && (t != ':')) strcat(tdir, "/");
  59.         }
  60.         strcat(tdir, fib->fib_FileName);
  61.         if (fib->fib_DirEntryType > 0)
  62.         {
  63.           tlock = (ULONG) Lock(tdir, ACCESS_READ);
  64.           ScanDir(tlock, tdir);  /** it was a directory so recurse **/
  65.           UnLock(tlock);
  66.         }
  67.         else
  68.           printf("%s\n", tdir);
  69.       }
  70.     }
  71.     FreeMem(fib, (long) sizeof(struct FileInfoBlock));
  72.   }
  73. }
  74.  
  75. main(argc, argv)
  76. int argc;
  77. char *argv[];
  78. {
  79.   ULONG root;
  80.   struct FileInfoBlock *fib;
  81.  
  82.   fib = (struct FileInfoBlock *) AllocMem((long) sizeof(struct FileInfoBlock), 0L);
  83.   if (fib)
  84.   {
  85.     if (argc == 1)
  86.     {
  87.       root = (ULONG) Lock("", ACCESS_READ);
  88.       if (Examine(root, fib))
  89.       {
  90.         if (fib->fib_DirEntryType > 0)
  91.           ScanDir(root, argv[argc]);
  92.       }
  93.       UnLock(root);
  94.     }
  95.     else
  96.     {
  97.       while (--argc)
  98.       {
  99.         root = (ULONG) Lock(argv[argc], ACCESS_READ);
  100.         if (Examine(root, fib))
  101.         {
  102.           if (fib->fib_DirEntryType > 0)
  103.             ScanDir(root, argv[argc]);
  104.         }
  105.         UnLock(root);
  106.       }
  107.     }
  108.     FreeMem(fib, (long) sizeof(struct FileInfoBlock));
  109.   }
  110. }
  111.  
  112.