Mega Code Archive

 
Categories / Delphi / Examples
 

Getfiles

How to recusively list all files in directories. procedure GetFiles(Result: TStrings; Path: string; IncludePath: Boolean = False); var R: Integer; SR: TSearchRec; ThePath: string; begin Assert(Result <> nil, 'Result is Nill'); ThePath := ExtractFilePath(Path); ThePath := IncludeTrailingBackSlash(ThePath); R := FindFirst(Path, faAnyFile, SR); while R = 0 do begin if IncludePath then Result.Add(ThePath + SR.Name) else Result.Add(SR.Name); R := FindNext(SR); end; FindClose(SR); end;