home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / murutil / where.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1988-11-22  |  2.5 KB  |  106 lines

  1. PROGRAM WHERE;
  2.  
  3. {  Turbo Pascal V4.0 file search utility.
  4.  
  5.    WHERE searches the entire default drive for the specified file or
  6.    files.  Wildcards are accepted.
  7.  
  8.    Examples:
  9.  
  10.               WHERE *.BAT   finds all files with an extension of BAT.
  11.  
  12.               WHERE F*.FOR  finds all files whose name starts with "F"
  13.                             with an extension of FOR.
  14.  
  15.               WHERE *.~??   finds all files whose extension starts with
  16.                             a "~".
  17.  
  18.    The output of this program can be redirected.
  19.  
  20.    Example:   WHERE *.PAS > PASC.LIS
  21.  
  22.    Program by Harry M. Murphy,  3 October 1988.  }
  23.  
  24. USES
  25.     DOS;
  26.  
  27. VAR
  28.     HIT    : BOOLEAN;
  29.     HOME   : STRING;
  30.     I      : INTEGER;
  31.     TARGET : STRING[12];
  32.     TOPDIR : STRING[3];
  33.  
  34. { -------------------------------- }
  35.  
  36. PROCEDURE SCANDIRECT;
  37.  
  38. {  This recursive procedure first scans all ordinary files  for
  39.    matches with the target and then recursively calls itself to
  40.    scan any and all subdirectories for matches.
  41.  
  42.    Procedure by Harry M. Murphy,  3 October 1988.  }
  43.  
  44. CONST
  45.     DIRF = $10;
  46.     LOOK = $06;
  47.  
  48. VAR
  49.     DIR  : STRING;
  50.     SRCH : SEARCHREC;
  51.  
  52. BEGIN
  53.  
  54.   {  First, scan for all ordinary matching files.  }
  55.   GETDIR(0,DIR);
  56.   FINDFIRST(TARGET,LOOK,SRCH);
  57.   WHILE DOSERROR = 0 DO
  58.     BEGIN
  59.       HIT := TRUE;
  60.       WRITELN(SRCH.NAME:12,' in ',DIR);
  61.       FINDNEXT(SRCH)
  62.     END;
  63.  
  64.   {  Then recur to scan all subdirectories.  }
  65.   FINDFIRST('*.*',DIRF,SRCH);
  66.   WHILE DOSERROR = 0 DO
  67.     BEGIN
  68.       IF (SRCH.ATTR = DIRF) AND (SRCH.NAME[1] <> '.')
  69.         THEN
  70.           BEGIN
  71.             CHDIR(SRCH.NAME);
  72.             SCANDIRECT;
  73.             CHDIR('..')
  74.           END;
  75.       FINDNEXT(SRCH)
  76.     END
  77.  
  78. END { Procedure SCANDIRECT };
  79.  
  80. { -------------------------------- }
  81.  
  82. BEGIN
  83.   IF PARAMCOUNT = 1
  84.     THEN
  85.       BEGIN
  86.         ASSIGN(OUTPUT,'');
  87.         REWRITE(OUTPUT);
  88.         TARGET := PARAMSTR(1);
  89.         FOR I := 1 TO LENGTH(TARGET) DO TARGET[I] := UPCASE(TARGET[I]);
  90.         IF POS('.',TARGET) = 0 THEN TARGET := TARGET+'.*';
  91.         GETDIR(0,HOME);
  92.         TOPDIR := HOME;
  93.         CHDIR(TOPDIR);
  94.         HIT := FALSE;
  95.         SCANDIRECT;
  96.         CHDIR(HOME);
  97.         IF (NOT HIT) THEN WRITELN('No occurrences of ',TARGET,
  98.                                   ' found while searching ',TOPDIR)
  99.       END
  100.     ELSE
  101.       BEGIN
  102.         WRITELN('Syntax is:  "WHERE filemask".');
  103.         WRITELN('  Example:  "WHERE *.PAS".')
  104.       END
  105. END.
  106.