Einzelnen Beitrag anzeigen

delnu
(Gast)

n/a Beiträge
 
#4

AW: Search for multiple files at once in PC

  Alt 1. Jan 2013, 15:38
Maybe that this code not exactly feed your needs, but I used it in a big program to check if some of the filetypes are found in the given path.

In a checklistbox I gave some names of filetypes, then I let the program search for it in a given path. If same type matches in this directory, this type is checked in the checklistbox. Instead of using the checkboxes you may use boolean variables that shows, if the searched file/fileytpe was found.
Delphi-Quellcode:
PROCEDURE FindTypes(s:string); // "s" ist the path to search in
VAR
 cnt: integer;
 pfad,
 n: string;
 sr: TSearchRec;

 PROCEDURE SUBB;
 BEGIN
  WITH Form1 DO BEGIN
   n:=AnsiUpperCase(ExtractFileExt(sr.name));
   IF n='.BMP'
   THEN CheckListBox1.checked[ 0]:=TRUE;
   IF n='.GIF'
   THEN CheckListBox1.checked[ 1]:=TRUE;
   IF n='.ICO'
   THEN CheckListBox1.checked[ 2]:=TRUE;
   IF n='.JPG'
   THEN CheckListBox1.checked[ 3]:=TRUE;
   IF n='.PCX'
   THEN CheckListBox1.checked[ 4]:=TRUE;
   IF n='.PNG'
   THEN CheckListBox1.checked[ 5]:=TRUE;
   IF n='.TIF'
   THEN CheckListBox1.checked[ 6]:=TRUE;
   IF n='.WMF'
   THEN CheckListBox1.checked[ 7]:=TRUE;
  END;
 END; { PROCEDURE SUBB }

BEGIN { PROCEDURE FindTypes }
 WITH Form1 DO BEGIN
  FOR cnt:=0 TO CheckListBox1.Items.count-1 DO CheckListBox1.checked[cnt]:=FALSE;
  IF DirectoryExists(s)
  THEN pfad:=s
  ELSE pfad:=ExtractFilePath(s);
  IF pfad[length(pfad)]<>'\THEN pfad:=pfad+'\';
{ showmessage(pfad+^J^M+s);}
  IF autoFind
  THEN BEGIN
   IF FindFirst(pfad+'*.*',faAnyFile,sr)=0
   THEN BEGIN
    WHILE FindNext(sr) = 0
    DO BEGIN
     subb;
    END;
    FindClose(sr);
   END;
  END ELSE BEGIN
   IF FindFirst(pfad+'*.*',faAnyFile,sr)=0
   THEN BEGIN
    WHILE FindNext(sr) = 0
    DO IF AnsiUpperCase(sr.name)=extractFileName(s)
    THEN BEGIN
     subb;
    END;
    FindClose(sr);
   END;
  END;
//SetPicTypes;
 END;
END; { PROCEDURE FindTypes }
edit :
Just I don't know, what the boolean variable "autofind" was. I wrote the program several years ago and just took that bit of the code.

Instead of the checklistbox you can use a listbox with files to search for and then put the results into another listbox with the whole result ( drive + path + filename ) ...

Geändert von delnu ( 1. Jan 2013 um 15:48 Uhr) Grund: edit
  Mit Zitat antworten Zitat