home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / h / htmix20.zip / FF.ZIP / FFE.PAS < prev    next >
Pascal/Delphi Source File  |  1992-07-12  |  4KB  |  141 lines

  1. program FileFinderExecuter;
  2. {┌──────────────────────────────── INFO ────────────────────────────────────┐}
  3. {│ File    : FFE.PAS                                                        │}
  4. {│ Author  : Harald Thunem                                                  │}
  5. {│ Purpose : Find files and execute command on them.                        │}
  6. {│ Updated : July 10 1992                                                   │}
  7. {└──────────────────────────────────────────────────────────────────────────┘}
  8.  
  9. {────────────────────────── Compiler directives ─────────────────────────────}
  10. {$A+   Word align data                                                       }
  11. {$B-   Short-circuit Boolean expression evaluation                           }
  12. {$E-   Disable linking with 8087-emulating run-time library                  }
  13. {$G+   Enable 80286 code generation                                          }
  14. {$R-   Disable generation of range-checking code                             }
  15. {$S-   Disable generation of stack-overflow checking code                    }
  16. {$V-   String variable checking                                              }
  17. {$X-   Disable Turbo Pascal's extended syntax                                }
  18. {$N+   80x87 code generation                                                 }
  19. {$D-   Disable generation of debug information                               }
  20. {────────────────────────────────────────────────────────────────────────────}
  21. {$M $4000,0,0} { Set memory specifications }
  22.  
  23. uses Dos;
  24.  
  25. var  MainDir    : DirStr;
  26.      SearchFile,
  27.      Command    : string;
  28.  
  29. procedure ShowOptions;
  30. begin
  31.   WriteLn('Program : FFE  --  File Finder / Executer 2.0');
  32.   WriteLn('Author  : Harald Thunem');
  33.   WriteLn('Purpose : Find files and execute any command on them');
  34.   WriteLn('Updated : July 10 1992');
  35.   WriteLn;
  36.   WriteLn('Usage   : FFE [D:]SearchFile [Command]');
  37.   WriteLn;
  38.   WriteLn('          SearchFile may contain wildcard ("*.PAS","NU*.?XE")');
  39.   WriteLn('          Command is optional. Insert @ where you want the filename to appear.');
  40.   WriteLn('          Ex:  FFE *.bak del @');
  41.   Halt(1);
  42. end;
  43.  
  44.  
  45. function UpcaseStr(s: string): string;
  46. var i: byte;
  47. begin
  48.   for i := 1 to Length(s) do
  49.     s[i] := Upcase(s[i]);
  50.   UpcaseStr := s;
  51. end;
  52.  
  53.  
  54. procedure GetCommands;
  55. var i: byte;
  56.     s: string;
  57.     s2: string[2];
  58. begin
  59.   SearchFile := '';
  60.   GetDir(0,MainDir);
  61.   MainDir := Copy(MainDir,1,2);
  62.   if ParamCount=0 then ShowOptions;
  63.  
  64.   SearchFile := UpcaseStr(ParamStr(1));
  65.  
  66.   s := '';
  67.   if ParamCount>1 then
  68.   for i := 2 to ParamCount do
  69.     s := s + ParamStr(i) + ' ';
  70.   s := UpcaseStr(s);
  71.   if Pos('@',s)>0 then
  72.     Command := s
  73.   else Command := '';
  74.  
  75.   if Pos(':',SearchFile)>0 then
  76.   begin
  77.     MainDir := SearchFile[1]+':';
  78.     Delete(SearchFile,1,2);
  79.   end;
  80.   if SearchFile[1]='\' then Delete(SearchFile,1,1);
  81. end;
  82.  
  83.  
  84. {$F+}procedure ProceedFile(MainDir: PathStr;  S: SearchRec);{$F-}
  85. var CommandS: string;
  86.     l: byte;
  87. begin
  88.   if Command='' then
  89.     WriteLn(MainDir+S.Name)
  90.   else begin
  91.     CommandS := Command;
  92.     l := Pos('@',CommandS);
  93.     Delete(CommandS,l,1);
  94.     Insert(MainDir+S.Name,CommandS,l);
  95.     WriteLn(CommandS);
  96.     SwapVectors;
  97.     Exec(GetEnv('COMSPEC'),'/C '+CommandS);
  98.     SwapVectors;
  99.     if DosError<>0 then
  100.       WriteLn('Could not execute ',CommandS,'. Dos error # ',DosError);
  101.   end;
  102. end;
  103.  
  104.  
  105. procedure Search(MainDir: DirStr;  SearchFile: string; Attribute: word);
  106. var S: SearchRec;
  107. begin
  108.   { Search for files }
  109.   if Attribute and Directory <> Directory then
  110.     Dec(Attribute,Directory);
  111.   MainDir := MainDir + '\';
  112.   FindFirst(MainDir+SearchFile,Attribute,S);
  113.   while DosError = 0 do
  114.   begin
  115.     if (S.Attr and Attribute<>0) or
  116.        (S.Attr and Directory<>0) then
  117.        ProceedFile(MainDir,S);
  118.     FindNext(S);
  119.   end;
  120.  
  121.   { Search for sub-directories }
  122.   FindFirst(MainDir+'*.*',Directory,S);
  123.   while DosError = 0 do
  124.   begin
  125.     if (S.Attr and Directory<>0) and (S.Name[1]<>'.') then
  126.       Search(MainDir+S.Name,SearchFile,Attribute);
  127.     FindNext(S);
  128.   end;
  129. end;
  130.  
  131.  
  132. begin
  133.   WriteLn('FFE 2.0                                                      Written by H.Thunem');
  134.   WriteLn('─────────────────────────────────────────────────────────────────────────');
  135.   GetCommands;
  136.   WriteLn('File-spec: ',SearchFile);
  137.   WriteLn('Command  : ',Command);
  138.   WriteLn;
  139.   Search(MainDir,SearchFile,AnyFile);
  140. end.
  141.