Message-ID: <3B26AFAB.FD428C89@borland.newsgroups> Date: Wed, 13 Jun 2001 10:11:23 +1000 From: Charles Hacker X-Mailer: Mozilla 4.76 [en] (Win95; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: borland.public.delphi.students Subject: Re: Finding files on the entire disk References: <3b269836$1_2@dnews> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 132.234.46.2 X-Trace: dnews 992391094 132.234.46.2 (12 Jun 2001 17:11:34 -0700) Lines: 42 Path: dnews Xref: dnews borland.public.delphi.students:12250 JJ wrote: > > Is there a way in Delphi to programatically search all the directories on a > disk for a specific file? CODE FOR RECURSIVE SEARCH FOR A FILE procedure GetFiles(APath: string; AExt: string; AList: TStrings; ARecurse: boolean); var theExt: string; searchRec: SysUtils.TSearchRec; begin if APath[Length(APath)] <> '\' then APath := APath + '\'; AList.AddObject(APath, Pointer(-1)); if FindFirst(APath + '*.*', faAnyFile, searchRec) = 0 then repeat with searchRec do begin if (Name <> '.') and (Name <> '..') then if (Attr and faDirectory <= 0) then begin theExt := '*' + UpperCase(ExtractFileExt(searchRec.Name)); if (AExt = '*.*') or (theExt = UpperCase(AExt)) then AList.AddObject(searchRec.Name, Pointer(0)) end else begin if ARecurse then begin GetFiles(APath + Name + '\', AExt, AList, ARecurse); end; end; end; {with searchRec...} Application.ProcessMessages; until FindNext(searchRec) <> 0; SysUtils.FindClose(searchRec); end; -- Charles Hacker Lecturer in Electronics and Computing School of Engineering Griffith University - Gold Coast Australia