Difference between revisions of "FindAllFiles/ru"

From Free Pascal wiki
Jump to navigationJump to search
(Created page with "{{FindAllFiles}} Unit: Lazarus fileutil См.также: * http://lazarus-ccr.sourceforge.net/docs/lcl/fileutil/findallfiles.html * http://lazarus-ccr.sourceforge.n...")
 
Line 16: Line 16:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
'''FindAllFiles''' looks for files matching the searchmask in the SearchPath directory and if specified its children and populates a [[TStrings|stringlist]] with the resulting filenames.
+
'''FindAllFiles''' ищет файлы, соответствующие маске поиска, в каталоге SearchPath и, если указано, в его вложенных папках, и заполняет [[TStrings|stringlist]] результирующими именами файлов.
  
The mask can be a single mask like you can use with the FindFirst/FindNext functions,
+
Маска может быть единственной маской, которую вы можете использовать с функциями FindFirst/FindNext, или она может состоять из списка масок, разделенных [[Semicolon|точкой с запятой(;)]].<br>
or it can consist of a list of masks, separated by a [[Semicolon|semicolon (;)]].<br>
+
Пробелы в маске рассматриваются как литералы.
Spaces in the mask are treated as literals.
 
  
There are two overloaded versions of this routine. The first one is a '''[[Procedure|procedure]]''' and assumes that the receiving stringlist already has been created.
+
Есть две перегруженные версии этой процедуры. Первая из них представляет собой '''[[Procedure/ru|процедуру]]''' и предполагает, что получающий список строк уже создан.
The second one is a '''[[Function|function]]''' which creates the stringlist internally and returns it as a function result. In both cases the stringlist must be destroyed by the calling procedure.
+
Вторая - это '''[[Function/ru|функция]]''', которая создает список строк внутри себя и возвращает его как результат функции. В обоих случаях список строк должен быть уничтожен вызывающей процедурой.
  
'''Example:'''
+
'''Пример:'''
 
<syntaxhighlight>
 
<syntaxhighlight>
 
uses  
 
uses  

Revision as of 18:07, 23 February 2019

English (en) español (es) suomi (fi) français (fr) polski (pl) русский (ru)

Unit: Lazarus fileutil

См.также:

procedure FindAllFiles(AList: TStrings; const SearchPath: String;
  SearchMask: String = ''; SearchSubDirs: Boolean = True; DirAttr: Word = faDirectory); 

function FindAllFiles(const SearchPath: String; SearchMask: String = '';
  SearchSubDirs: Boolean = True): TStringList;

FindAllFiles ищет файлы, соответствующие маске поиска, в каталоге SearchPath и, если указано, в его вложенных папках, и заполняет stringlist результирующими именами файлов.

Маска может быть единственной маской, которую вы можете использовать с функциями FindFirst/FindNext, или она может состоять из списка масок, разделенных точкой с запятой(;).
Пробелы в маске рассматриваются как литералы.

Есть две перегруженные версии этой процедуры. Первая из них представляет собой процедуру и предполагает, что получающий список строк уже создан. Вторая - это функция, которая создает список строк внутри себя и возвращает его как результат функции. В обоих случаях список строк должен быть уничтожен вызывающей процедурой.

Пример:

uses 
  ..., FileUtil, ...
var
  PascalFiles: TStringList;
begin
  PascalFiles := TStringList.Create;
  try
    FindAllFiles(PascalFiles, LazarusDirectory, '*.pas;*.pp;*.p;*.inc', true); //find e.g. all pascal sourcefiles
    ShowMessage(Format('Found %d Pascal source files', [PascalFiles.Count]));
  finally
    PascalFiles.Free;
  end;

// or

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;

IMPORTANT NOTE: The function "FindAllFiles" creates the stringlist internally. This may look very convenient at first sight, but it is very easy to create memory leaks that way:

  // DON'T EVER DO THIS !!!! - There is no way to destroy the stringlist created by FindAllFiles.
  Listbox1.Items.Assign(FindAllFiles(LazarusDirectory, '*.pas;*.pp;*.p;*.inc', true);
Light bulb  Примечание: 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