home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_01_02 / 1n02060a < prev    next >
Text File  |  1990-07-09  |  1KB  |  55 lines

  1. /*
  2. **  Listing 6 - A simple recursive directory lister
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7.  
  8. #ifdef __ZTC__
  9.  #include <mflfiles.h>  /* ZTC doesn't do recursive find
  10.                            first/next...  */
  11.  #include <msport.h>    /* ...so use MFLZT library functions         */
  12. #elif defined(__TURBOC__)
  13.  #include <dir.h>
  14.  #include <dos.h>
  15.  #define _dos_findfirst(f,a,b) findfirst(f,b,a)
  16.  #define _dos_findnext(b) findnext(b)
  17.  #define find_t ffblk
  18.  #define _A_SUBDIR FA_DIREC
  19.  #define attrib ff_attrib
  20.  #define name ff_name
  21. #else                   /* assume MSC/QC                             */
  22.  #include <dos.h>
  23.  #include <errno.h>
  24. #endif
  25.  
  26. #ifndef SUCCESS
  27.  #define SUCCESS 0
  28. #endif
  29.  
  30. void do_dir(char *path)
  31. {
  32.         char search[67], new[67];
  33.         struct find_t ff;
  34.  
  35.         strcat(strcpy(search, path), "\\*.*");
  36.         if (SUCCESS == _dos_findfirst(search, 0xff, &ff)) do
  37.         {
  38.                 printf("%s\\%s\n", path, ff.name);
  39.                 if (ff.attrib & _A_SUBDIR && '.' != *ff.name)
  40.                 {
  41.                         strcat(strcat(strcpy(new, path), "\\"), ff.name);
  42.                         do_dir(new);
  43.                 }
  44.         } while (SUCCESS == _dos_findnext(&ff));
  45. }
  46.  
  47. main(int argc, char *argv[])
  48. {
  49.         char *dir = ".";
  50.  
  51.         if (1 < argc)
  52.                 dir = argv[1];
  53.         do_dir(dir);
  54. }
  55.