DelphiBasics
FindNext
Function
Find the next file after a successful FindFirst SysUtils unit
 function FindNext(var SearchResults TSearchRec):Integer;
Description
The FindNext function looks for the next matching file, as defined in the search criteria given by the preceding FindFirst call. The found file details are stored in SearchResults and the return value is 0. Otherwise the return value is negative.
 
You must have performed a successful FindFirst before calling this routine.
 
You must call FindClose after calling FindNext for the last time in order to free up resources.
Related commands
FileSearchSearch for a file in one or more directories
FindCloseCloses a successful FindFirst file search
FindFirstFinds all files matching a file mask and attributes
TSearchRecRecord used to hold data for FindFirst and FindNext
 Download this web site as a Windows program.




 
Example code : Search for all Unit1.d* files in the current directory
var
  searchResult : TSearchRec;

begin
  // Try to find regular files matching Unit1.d* in the current dir
  if FindFirst('Unit1.d*', faAnyFile, searchResult) = 0 then
  begin
    repeat
      ShowMessage('File name = '+searchResult.Name);
      ShowMessage('File size = '+IntToStr(searchResult.Size));
    until FindNext(searchResult) <> 0;

    // Must free up resources used by these successful finds
    FindClose(searchResult);
  end;
end;
Show full unit code
  File name = Unit1.dcu
  File size = 4382
  File name = Uni1.dfm
  File size = 524
  File name = Uni1.ddp
  File size = 51
 
Delphi Programming © Neil Moffatt 2002 - 2022. All rights reserved.  |  Home Page