ファイルサイズを取得する
DelphiにはFileSize関数というのがありますが、これはテキストファイルには使用できません。
テキストファイル、バイナリファイル関係無くサイズを調べるには FindFirst 関数を使用します。
| ■ ファイルサイズを調べる例 |
procedure TForm1.Button1Click(Sender: TObject);
var
Rec : TSearchRec;
intSize : integer;
begin
{ ファイルの検索 }
if FindFirst('D:\Borland\Delphi 3\bin\Delphi32.exe', faAnyFile, Rec) = 0 then
begin
{ サイズの取得 }
intSize := Rec.Size;
{ KBに変換して表示 }
Label1.Caption := IntToStr(intSize div 1024) + ' KB';
end;
FindClose(Rec);
end;
|