Author: Lou Adler
I am trying to populate a TStringlist with files matching *.pas;*.dfm;*.dpr etc.
from the current folder which is easy enough, but I also want to search sub folder
for the same file types and keep their folder structure so that I can copy all the
files in one go to another folder and then to CD for extra backups.
Answer:
1 2 procedure GetFileList(const Path: string; const Extensions: string; FileList:
3 TStrings);
4 var5 SR: TSearchRec;
6 begin7 if FindFirst(Path + '*.*', faAnyFile, SR) = 0 then8 try9 repeat10 if (SR.Attr and faDirectory) > 0 then11 begin12 if SR.Name[1] <> '.' then13 GetFileList(Path + SR.Name + '\', Extensions, FileList)
14 end15 elseif Pos(UpperCase(ExtractFileExt(SR.Name)), Extensions) > 0 then16 FileList.Add(Path + SR.Name);
17 until18 FindNext(SR) <> 0;
19 finally20 FindClose(SR);
21 end;
22 end;
23 24 //Usage:25 26 GetFileList('c:\', '.PAS .FRM .DPR', MyStringList);