FindAllFiles

From Free Pascal wiki
Revision as of 22:08, 11 December 2012 by Chronos (talk | contribs)
Jump to navigationJump to search

Template:Translate

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

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 file name or...todo finish: can wildcards * and ? be used here?

Example:

uses 
...
fileutil
...
var
  SVNFiles: TStringList;
begin
  //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
  try
    if SVNFiles.Count > 0 then
    begin
      // Just get first result.
      showmessage('Found an svn executable: '+SVNFiles.Strings[0]);
    end;
  finally
    SVNFiles.Free;
  end;