Difference between revisions of "FindAllFiles"

From Free Pascal wiki
Jump to navigationJump to search
m
Line 14: Line 14:
 
'''findallfiles''' looks for files matching the searchmask in the SearchPath directory and if specified its children and returns a stringlist with the resulting filenames.
 
'''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 file name or...todo finish: can wildcards * and ? be used here?
+
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 (;).<br>
 +
Spaces in the mask are treated as literals.
  
 
Example:
 
Example:
Line 23: Line 25:
 
...
 
...
 
var
 
var
   SVNFiles: TStringList;
+
   PascalFiles: TStringList;
 
begin
 
begin
 
   //No need to create the stringlist; the function does that for you
 
   //No need to create the stringlist; the function does that for you
   SVNFiles := FindAllFiles(FSVNDirectory, 'svn' + LazUtils.GetExeExt, true); //find e.g. all svn.exe
+
   PascalFiles := FindAllFiles(LazarusDirectory, '*.pas;*.pp;*.p;*.inc', true); //find e.g. all pascal sourcefiles
 
   try
 
   try
     if SVNFiles.Count > 0 then
+
     showmessage(Format('Found %d Pascal source files',[PascalFiles.Count]));
    begin
 
      // Just get first result.
 
      showmessage('Found an svn executable: '+SVNFiles.Strings[0]);
 
    end;
 
 
   finally
 
   finally
     SVNFiles.Free;
+
     PascalFiles.Free;
 
   end;
 
   end;
  

Revision as of 15:46, 3 August 2013

Template:Translate

Unit: Lazarus fileutil (UTF-8 replacements for FPC RTL code and additional file/directory handling)

See also:

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;