Difference between revisions of "FindAllFiles"
From Lazarus wiki
Jump to navigationJump to searchm (moved findallfiles to FindAllFiles) |
m |
||
Line 34: | Line 34: | ||
PascalFiles.Free; | PascalFiles.Free; | ||
end; | end; | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | {{Note|If you want to use this function in command line programs, add a project requirement for LCLBase, which will not pull in the entire LCL}} | ||
− | |||
[[category:Lazarus]] | [[category:Lazarus]] | ||
[[category:fileutil]] | [[category:fileutil]] | ||
[[Category:Code]] | [[Category:Code]] |
Revision as of 10:04, 29 September 2014
Unit: Lazarus fileutil (UTF-8 replacements for FPC RTL code and additional file/directory handling)
See also:
- http://lazarus-ccr.sourceforge.net/docs/lcl/fileutil/findallfiles.html
- http://lazarus-ccr.sourceforge.net/docs/lcl/fileutil/tfilesearcher.html
function FindAllFiles(const SearchPath: String; SearchMask: String = '';
SearchSubDirs: Boolean = True): TStringList;
findallfiles looks for files matching the searchmask in the SearchPath directory and if specified its children and returns a stringlist with the resulting filenames.
The mask can be a single mask like you can use with the FindFirst/FindNext functions,
or it can consist of a list of masks, separated by a semicolon (;).
Spaces in the mask are treated as literals.
Example:
uses
...
fileutil
...
var
PascalFiles: TStringList;
begin
//No need to create the stringlist; the function does that for you
PascalFiles := FindAllFiles(LazarusDirectory, '*.pas;*.pp;*.p;*.inc', true); //find e.g. all pascal sourcefiles
try
showmessage(Format('Found %d Pascal source files',[PascalFiles.Count]));
finally
PascalFiles.Free;
end;
Note: If you want to use this function in command line programs, add a project requirement for LCLBase, which will not pull in the entire LCL