TFile.Size

I use very often the System.IOUtils units with the wonderful classes/records TPath, TDirectory and TFile. They are much more comfortable than the old functions from System.SysUtils like FindFirst etc..

But there is one method I’m really missing: It is the size of a file. For sure there are some workarounds but I think that this method belongs to TFile. That’s why I wrote a small helper class:

type
  TFileHelper = record helper for TFile
  public
    class function Size(const APath: string): Int64; static;
  end;

{ TFileHelper }

class function TFileHelper.Size(const APath: string): Int64;
var
  pStream: TFileStream;
begin
  pStream := OpenRead(APath);
  try
    Result := pStream.Size;
  finally
    pStream.Free;
  end;
end;

I will try to convince Marco or Jim to add this method to the next release. So stay tuned.

This entry was posted in C++-Builder, Delphi, RAD Studio 10.2 Tokyo, Uncategorized. Bookmark the permalink.