home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / tug__002 / scan.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1988-08-08  |  5.5 KB  |  191 lines

  1. {TUG PDS CERT 1.01 (Pascal)
  2.  
  3. ==========================================================================
  4.  
  5.                   TUG PUBLIC DOMAIN SOFTWARE CERTIFICATION
  6.  
  7. The Turbo User Group (TUG) is recognized by Borland International as the
  8. official support organization for Turbo languages.  This file has been
  9. compiled and verified by the TUG library staff.  We are reasonably certain
  10. that the information contained in this file is public domain material, but
  11. it is also subject to any restrictions applied by its author.
  12.  
  13. This diskette contains PROGRAMS and/or DATA determined to be in the PUBLIC
  14. DOMAIN, provided as a service of TUG for the use of its members.  The
  15. Turbo User Group will not be liable for any damages, including any lost
  16. profits, lost savings or other incidental or consequential damages arising
  17. out of the use of or inability to use the contents, even if TUG has been
  18. advised of the possibility of such damages, or for any claim by any
  19. other party.
  20.  
  21. To the best of our knowledge, the routines in this file compile and function
  22. properly in accordance with the information described below.
  23.  
  24. If you discover an error in this file, we would appreciate it if you would
  25. report it to us.  To report bugs, or to request information on membership
  26. in TUG, please contact us at:
  27.  
  28.              Turbo User Group
  29.              PO Box 1510
  30.              Poulsbo, Washington USA  98370
  31.  
  32. --------------------------------------------------------------------------
  33.                        F i l e    I n f o r m a t i o n
  34.  
  35. * DESCRIPTION
  36. Turbo Pascal V4.0 code to scan all directories on a disk. As configured
  37. only displays the name of each directory (like DOS's TREE). But you can
  38. add your own code to make it do whatever you want.
  39.  
  40. * ASSOCIATED FILES
  41.  
  42. * CHECKED BY
  43. DRM - 08/08/88
  44.  
  45. * KEYWORDS
  46. TURBO PASCAL V4.0 DIRECTORY TREE
  47.  
  48. ==========================================================================
  49. }
  50. Program Scan;
  51.  
  52. {TP4 code to scan all directories on a disk and allow the
  53.  program to do something in each directory.  The routine
  54.  that works with the files in each directory is called
  55.  ProcessFilesInFoundDirectory.  All it does here is
  56.  display the pathname of the found directory.  Substitute
  57.  your own code using FindFirst/FindNext within the found
  58.  directory.}
  59.  
  60. Uses Dos,Crt;
  61.  
  62. const
  63.   SignOn = 'Directory Scan';
  64.   Notice = 'Copyright (c) 1988 Bayshore Designs, Inc.';
  65.   Notice1= 'Permission given to modify and use for non-commercial purposes.';
  66.   Notice2= 'All other rights reserved.';
  67.  
  68. var
  69.   DirList    : array[1..500] of String[64]; {Array to hold names of previously found directories}
  70.   DirInfo    : SearchRec; {Defined in DOS Unit for FindFirst call}
  71.   i          : integer; {Index for DirList array}
  72.   IsNewDir,
  73.   done       : boolean;
  74.   FoundDir,
  75.   name       : string[64];
  76.   TestDir,
  77.   StartDir,
  78.   CurDir     : string[64];
  79.  
  80. Procedure DoSignOns;
  81.   begin
  82.     Writeln(SignOn);
  83.     Writeln(Notice);
  84.     Writeln(Notice1);
  85.     Writeln(Notice2);
  86.     Writeln;
  87.   end;
  88.  
  89. Function NotPreviouslyFound(d:string; s:string) : boolean;
  90.   var
  91.     j      : integer;
  92.     f      : file;
  93.     attrib : word;
  94.  
  95.   begin
  96.     If (s = '.') or (s = '..') then {Eliminate 'dot' entries}
  97.       begin
  98.         NotPreviouslyFound:=false;
  99.       end
  100.       else
  101.       begin
  102.         j:=1;
  103.         While j<i do
  104.           begin
  105.             If DirList[j]=d+s then {Check against previously found dirs}
  106.               begin
  107.                 NotPreviouslyFound:=false;
  108.                 j:=i+1;
  109.               end
  110.               else
  111.               begin
  112.                 j:=j+1;
  113.               end;
  114.           end;
  115.         If j=i then
  116.           begin
  117.             Assign(f,s);
  118.             GetFAttr(f,attrib);
  119.             If attrib and Directory <> 0 then {Check that it's a directory}
  120.               begin
  121.                 NotPreviouslyFound:=true;
  122.               end
  123.               else
  124.               begin
  125.                 NotPreviouslyFound:=false;
  126.               end;
  127.           end;
  128.       end;
  129.   end;
  130.  
  131. Procedure ProcessFilesInFoundDir;
  132.   begin
  133.  
  134.     {Substitute your specific FindFirst/FindNext code here to process
  135.      files in this directory in whatever way you'd like.  The next
  136.      two lines merely display the name of the found dir and do nothing
  137.      with the actual files in that directory.}
  138.  
  139.     GetDir(0,TestDir);
  140.     Writeln(TestDir);
  141.   end;
  142.  
  143. BEGIN
  144. DoSignOns;
  145. {Initialize}
  146. GetDir(0,StartDir);
  147. CurDir:=StartDir;
  148. ChDir('\');
  149. FoundDir:='\';
  150. i := 1; {index to DirList}
  151. done:=false;
  152.  
  153. {Scan until attempt is made to go 'above' root dir}
  154. While not done do
  155.   begin
  156.     IsNewDir:=false;
  157.     FindFirst('*.*',Directory,DirInfo);
  158.     FoundDir:=DirInfo.name;
  159.     While (not IsNewDir) and (DosError=0) do
  160.       begin
  161.         IsNewDir := NotPreviouslyFound(CurDir,DirInfo.name);
  162.         If (not IsNewDir) then
  163.           begin
  164.             FindNext(DirInfo);
  165.             FoundDir:=DirInfo.name;
  166.           end;
  167.       end;
  168.  
  169.     If IsNewDir then {Save it and keep going down the chain}
  170.       begin
  171.         DirList[i] := CurDir+FoundDir;
  172.         i := i+1;
  173.         ChDir(FoundDir);
  174.         GetDir(0,CurDir);
  175.       end
  176.       else
  177.       begin
  178.         ProcessFilesInFoundDir; {i.e., do whatever you want with them}
  179.         GetDir(0,TestDir);
  180.         If Copy(TestDir,Length(TestDir),1) <> '\' then {check if we're done...}
  181.           begin
  182.             Chdir('..');
  183.             GetDir(0,CurDir);
  184.           end
  185.           else
  186.             done:=true;
  187.       end;
  188.   end;
  189.   Chdir(StartDir); {land the user in the starting directory...}
  190. END.
  191.