Beranda > Delphi > How to get the size of a file

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;
Iklan
Kategori:Delphi
  1. Belum ada komentar.
  1. No trackbacks yet.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: