On Wed, 14 Dec 2011 22:11:22 +0100, Hans-Peter Diettrich <drdiettri...@aol.com> wrote:

I wonder how to obtain the size of an file on disk. The only function I could find so far is FileSize, which requires an open File, but nothing for an file name :-(

ATM FileSize(TEXT) would help, too, but FileSize only accepts an FILE, not TEXT :-(

-- 8< --

function File_Size (const File_Name : String) : Int64;
var
   F : File;
begin
   {$HINTS OFF} // This *is* the initialization of "F".
   Assign (F, File_Name);
   {$HINTS ON}

   try
      Reset (F, 1);

      try
         exit (FileSize (F));
      finally
         Close (F);
      end {try};
   except
      on e : SysUtils.Exception do
         ; // Whatever...
   end {try};

   // default to error (reached only on exception)
   exit (-1);
end {File_Size};
-- 8< --

WFM.


Vinzent.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to