DelphiBasics
TSearchRec
Type
Record used to hold data for FindFirst and FindNext SysUtils unit
  type
    TSearchRec = record
      Time        : Integer;
      Size        : Integer;
      Attr        : Integer;
      Name        : TFileName;
      ExcludeAttr : Integer;  
      FindHandle  : THandle;
      FindData    : TWin32FindData;
  end;
Description
The TSearchRecord record type defines a data structure used to hold file search information for the FindFirst and FindNext routines.
 
Time  = Last modified file date and time
Size  = File size in bytes
Attr  = File attributes
Name  = File name

 
Where Attr can have these values :
 
faAnyFile  : Any file
faReadOnly  : Read-only files
faHidden  : Hidden files
faSysFile  : System files
faVolumeID  : Volume ID files
faDirectory  : Directory files
faArchive  : Archive files

 
Note : TFileName is a simple string type, but is used to hold file names.
 
The remaining fields are used internally by the find routines - you should not update them.
Related commands
FileSearch Search for a file in one or more directories
FindClose Closes a successful FindFirst file search
FindFirst Finds all files matching a file mask and attributes
FindNext Find the next file after a successful FindFirst
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 Download this web site as a Windows program.




 
Example code : Find all Unit1.d* regular file names and sizes in the current directory
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
 
unit Unit1;
 
interface
 
uses
  SysUtils,   // Unit containing the TSearchRec command
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
 
var
  
Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);

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;
 
end.
Hide 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 - 2017. All rights reserved.  |  Home Page