[fpc-devel] Determin file size - how?
Vinzent Höfler
JeLlyFish.software at gmx.net
Wed Dec 14 23:41:08 CET 2011
On Wed, 14 Dec 2011 22:11:22 +0100, Hans-Peter Diettrich
<DrDiettrich1 at 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.
More information about the fpc-devel
mailing list