Einzelnen Beitrag anzeigen

danten

Registriert seit: 19. Feb 2012
Ort: Czech Republic, Prag
126 Beiträge
 
Delphi 10.1 Berlin Architect
 
#1

Search for multiple files at once in PC

  Alt 31. Dez 2012, 16:31
Hi all,
please help.
How do I write a function to search for multiple files on your computer at once.
I need to find files:
abcd.exe, 1234.ini, GHIJ.BAT, 0987.dat, tinyplay.exe !!
I use to find one set this feature:
Delphi-Quellcode:
function Tfindplayer.ScanL7(root, filemask: string; hitlist: String): Boolean;
  function ScanDirectory(var path: string): Boolean;
  var
    SRec: TSearchRec;
    pathlen: Integer;
    res: Integer;
  begin
    pathlen := Length(path);
    { first pass, files }
    res := FindFirst(path + filemask, faAnyfile+faHidden, SRec);
    If (FileExists(path+'tinyplay.exe') = True) then
      begin
        FScanAborted := True;
        sLabel24.Caption := ExtractShortPathName(ExcludeTrailingBackslash(sLabel24.Caption));
        sProgressBar1.Position := sProgressBar1.Position + 10;
        image12.Picture.Assign(x1);
        Exit;
      end;
    if res = 0 then
      try
        while res = 0 do
        begin
          hitlist := (path + SRec.Name);
          res := FindNext(SRec);
        end;
      finally
        FindClose(SRec);
      end;
    Application.ProcessMessages;
    Result := not (FScanAborted or Application.Terminated);
    if not Result then Exit;

    {second pass, directories}
    res := FindFirst(path + '*.*', faDirectory+faHidden, SRec);
    if res = 0 then
      try
        while (res = 0) and Result do
        begin
          if ((Srec.Attr and (faReadOnly or faHidden or faSysFile or faDirectory)) <> 0) and
            (Srec.Name <> '.') and
            (Srec.Name <> '..') then
          begin
            path := path + SRec.Name + '\';
            Result := ScanDirectory(path);
            SetLength(path, pathlen);
          end;
          res := FindNext(SRec);
        end;
      finally
        FindClose(SRec);
      end;
  end;

begin
  FScanAborted := False;
  Screen.Cursor := crHourglass;
  try
    Result := ScanDirectory(root);
  finally
    Screen.Cursor := crDefault
  end;
end;

function Tfindplayer.L7:boolean;
var
  Item: string;
  i: integer;
  ch: Char;
  root: string;
begin
  root := 'C:\';
  for ch := 'Ato 'Zdo
  begin
    root[1] := ch;
    case GetDriveType(PChar(root)) of
      DRIVE_FIXED, DRIVE_REMOTE:
        if not ScanL7(root,'tinyplay.exe', sLabel22.Caption) then
          Break;
    end;
  end;
end;
Thanks all.
Daniel
  Mit Zitat antworten Zitat