Delphi - 获取文件大小

GetFileSize获取文件大小

封装成如下函数,可以直接使用:

 1 ///函数功能:获取文件大小,单位取KB,小数自动进位
 2 ///参数:sFilePath文件全路径
 3 ///Result: 成功是返回文件大小,失败时返回'N'
 4 function GetFileSize(sFilePath: string): string;
 5 begin
 6   try
 7     result := IntToStr(Ceil(FileSizeByName(sFilePath) / 1024));
 8   except
 9     on E: Exception do
10     begin
11       result := 'N';
12       MessageDlg('Opps! Error Info[' + E.Message + ']', mtError, [mbOK], 0);
13       Abort;
14     end;
15   end;
16 end;
 

猜你喜欢

转载自www.cnblogs.com/jeremywucnblog/p/11438000.html