AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Search for multiple files at once in PC

Ein Thema von danten · begonnen am 31. Dez 2012 · letzter Beitrag vom 2. Jan 2013
Antwort Antwort
delnu
(Gast)

n/a Beiträge
 
#1

AW: Search for multiple files at once in PC

  Alt 1. Jan 2013, 14: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 14:48 Uhr) Grund: edit
  Mit Zitat antworten Zitat
Furtbichler
(Gast)

n/a Beiträge
 
#2

AW: Search for multiple files at once in PC

  Alt 1. Jan 2013, 15:40
Thank you, can you please give some code.
Why should I?

Ok, It's new year.

Delphi-Quellcode:
Procedure FindFiles (path : String; Files : TStrings; FoundFiles : TSTrings);
Var
  S : TSearchRec;

Begin
  if FindFirst(path+'\*.*',faAnyFile,S)=0 then begin
    repeat
      if S.Attr and faDirectory<>0 then
        FindFiles(path+'\'+s.Name,Files,FoundFiles)
      else if MatchesAny(S.Name, Files) then
        FoundFiles.Add(path+'\'+S.Name);
    until FindNext(S)<>0;
    FindClose(S);
  end;

    if FindFirst(path+'\*',faDirectory ,S)=0 then begin
    repeat
      if (s.Name<>'.') and (s.Name<>'..') Then
        FindFiles(path+'\'+s.Name,Files,FoundFiles)
    until FindNext(S)<>0;
    FindClose(S);
  end;
End;
The function 'MatchesAny' tries to match a filename with a list of given files (including wildcards). Maybe you can code this yourself.
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.659 Beiträge
 
Delphi 12 Athens
 
#3

AW: Search for multiple files at once in PC

  Alt 2. Jan 2013, 07:29
Maybe you want to give my component a try.
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:24 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz