home *** CD-ROM | disk | FTP | other *** search
- PROGRAM WHERE;
-
- { Turbo Pascal V4.0 file search utility.
-
- WHERE searches the entire default drive for the specified file or
- files. Wildcards are accepted.
-
- Examples:
-
- WHERE *.BAT finds all files with an extension of BAT.
-
- WHERE F*.FOR finds all files whose name starts with "F"
- with an extension of FOR.
-
- WHERE *.~?? finds all files whose extension starts with
- a "~".
-
- The output of this program can be redirected.
-
- Example: WHERE *.PAS > PASC.LIS
-
- Program by Harry M. Murphy, 3 October 1988. }
-
- USES
- DOS;
-
- VAR
- HIT : BOOLEAN;
- HOME : STRING;
- I : INTEGER;
- TARGET : STRING[12];
- TOPDIR : STRING[3];
-
- { -------------------------------- }
-
- PROCEDURE SCANDIRECT;
-
- { This recursive procedure first scans all ordinary files for
- matches with the target and then recursively calls itself to
- scan any and all subdirectories for matches.
-
- Procedure by Harry M. Murphy, 3 October 1988. }
-
- CONST
- DIRF = $10;
- LOOK = $06;
-
- VAR
- DIR : STRING;
- SRCH : SEARCHREC;
-
- BEGIN
-
- { First, scan for all ordinary matching files. }
- GETDIR(0,DIR);
- FINDFIRST(TARGET,LOOK,SRCH);
- WHILE DOSERROR = 0 DO
- BEGIN
- HIT := TRUE;
- WRITELN(SRCH.NAME:12,' in ',DIR);
- FINDNEXT(SRCH)
- END;
-
- { Then recur to scan all subdirectories. }
- FINDFIRST('*.*',DIRF,SRCH);
- WHILE DOSERROR = 0 DO
- BEGIN
- IF (SRCH.ATTR = DIRF) AND (SRCH.NAME[1] <> '.')
- THEN
- BEGIN
- CHDIR(SRCH.NAME);
- SCANDIRECT;
- CHDIR('..')
- END;
- FINDNEXT(SRCH)
- END
-
- END { Procedure SCANDIRECT };
-
- { -------------------------------- }
-
- BEGIN
- IF PARAMCOUNT = 1
- THEN
- BEGIN
- ASSIGN(OUTPUT,'');
- REWRITE(OUTPUT);
- TARGET := PARAMSTR(1);
- FOR I := 1 TO LENGTH(TARGET) DO TARGET[I] := UPCASE(TARGET[I]);
- IF POS('.',TARGET) = 0 THEN TARGET := TARGET+'.*';
- GETDIR(0,HOME);
- TOPDIR := HOME;
- CHDIR(TOPDIR);
- HIT := FALSE;
- SCANDIRECT;
- CHDIR(HOME);
- IF (NOT HIT) THEN WRITELN('No occurrences of ',TARGET,
- ' found while searching ',TOPDIR)
- END
- ELSE
- BEGIN
- WRITELN('Syntax is: "WHERE filemask".');
- WRITELN(' Example: "WHERE *.PAS".')
- END
- END.