Monday

Viewing File Size



To determine the size of a file, Delphi has provided the function filesize (var F): integer In this example the following program, I use the Windows API function GetFileSize (). Example Delphi program as follows: First step: design form with popertiey 2 Button, Edit1, OpenDialog The second step input the program listing as follows: 

 Procedure Tfrom. Button1Click(sender:Tobject);
var FileHendle : integer;
HightOrderSize :^Dword;
LowOrderSize : Dword;
begin
FileHendle:= 0;
try
FileHendle:= Fileopen(Edit1.text, fmOpenRead);
if FileHendle=-1 then
begin
ShowMessage('gagal membuka file');
exit;
end;
HightOrderSize:=nil;
LowOrderSize:=GetFilesize(fileHendle, HightOrderSize);
if LowOrderSize = INVALID_FILE_SIZE then
ShowMessage('gagal mendapatkan ukuran file')
else
if HightOrderSize <> nil then
Application.MessageBox('Ukuran file > 4,39 Gbyte' , 'info ukuran file', MB_OK or MB_ICONINFORMATION);
else
Application.MessageBox(PChar('Ukuran file : ' + IntToStr(LowOrderSize) + 'Byte') , 'info ukuran file' , MB_OK or MB_ICONINFORMATION);
finally
FileClose(FileHendle);
end;
end;

Procedure Tform. Button2Click(Sender: TObject);
begin
if OpenDialog1.Execute then
Edit1.Text := OpenDialog1.FileName;
end;

No comments:

Post a Comment

Related Posts with Thumbnails