«« Site Rescued »»

While the site is still going to move from its current host, a new site will now take its place. More Info.

The new site may have less content, but the core will now remain. And it will now play nicely with phones! Keep an eye on the DelphiDabbler Blog for news.

» Help

How to get the size of a file

   

Here is a function to get the size of a file by using the native Pascal I/O and file management routines. The function returns -1 if the file doesn't exist.

function GetFileSize(FName: string): Int64;
var
  ch: File;
  OldMode: Integer;
begin
  OldMode := FileMode;
  Result := -1;
  if not FileExists(FName) then Exit;
  try
    AssignFile(ch, FName);
    FileMode := 0;
    Reset(ch,1);
    Result := FileSize(ch);
  finally
    CloseFile(ch);
    FileMode := OldMode;
  end;
end;
Author: Joe Donth
Contributor: Joe Donth
Added: 2007-08-14
Last updated: 2007-08-14

« Return to contents »