home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol8n01.zip / DIRTREE.PAS < prev    next >
Pascal/Delphi Source File  |  1988-10-06  |  2KB  |  59 lines

  1. PROGRAM dirtree;
  2. { DIRTREE.pas
  3.   Directory tree display
  4.   written by Bill Roohi, 1988
  5. }
  6. USES dos;
  7.  
  8. CONST nested = 10; {up to 10 nested levels}
  9.  
  10. VAR dirinfo   : searchrec;
  11.   lastdir     : ARRAY[1..nested] OF STRING[12];
  12.   level       : Integer;
  13.   path, blank : STRING[150];
  14.   ok          : Boolean;
  15.  
  16. BEGIN
  17.   ok := True;                  {initialize      }
  18.   level := 0;                  {start at level 0}
  19.   FillChar(blank[1], 150, 32); {used for tabs   }
  20.   blank[0] := #150;
  21.   GetDir(0, path);             {get current path}
  22.   ChDir('\');                  {root directory  }
  23.  
  24.   Findfirst('*.*', anyfile, dirinfo); {start search    }
  25.   WHILE ok DO
  26.     BEGIN
  27.       WHILE (doserror = 0) AND
  28.             ((dirinfo.attr <> 16) OR
  29.              (dirinfo.name = '.') OR
  30.              (dirinfo.name = '..')) DO
  31.         Findnext(dirinfo);
  32.       IF (level = 0) AND (doserror <> 0) THEN
  33.         ok := False  { End of root - time to exit }
  34.       ELSE
  35.         IF (dirinfo.attr = 16) AND (doserror = 0) THEN
  36.           BEGIN                                 {subdir found}
  37.             WriteLn(Copy(blank, 1, level*4)+
  38.                                 dirinfo.name);  {display it  }
  39.             Inc(level);                         {next level  }
  40.             lastdir[level] := dirinfo.name;     {save subdir }
  41.             ChDir(dirinfo.name);                {new subdir  }
  42.             Findfirst('*.*', anyfile, dirinfo); {start search}
  43.           END
  44.         ELSE
  45.           IF (level <> 0) AND (doserror <> 0) THEN
  46.             BEGIN                                {end of subdir }
  47.               ChDir('..');                       {previous level}
  48.               Findfirst('*.*', anyfile, dirinfo);{start search  }
  49.               WHILE (doserror = 0) AND
  50.                    ((dirinfo.attr <> 16) OR
  51.                     (dirinfo.name <> lastdir[level])) DO
  52.                 Findnext(dirinfo);               {look for match}
  53.               Findnext(dirinfo);                 {skip past it  }
  54.               Dec(level);                        {previous level}
  55.             END;
  56.     END; {WHILE ok}
  57.   ChDir(path);                      {to original path}
  58. END.
  59.