返回顶部
扶摇直上九万里,展翅高飞岂可待。

计算文件大小

function GetFileSize(const FileName : string): DWORD;
var
  f : integer;
begin
  f := FileOpen(FileName, fmOpenRead);
  try
    Result := Windows.GetFileSize(f, nil);
  finally
    FileClose(f);
  end;
  if Result = $FFFFFFFF then Result := 0;
end;

function CalcFileSizeStr(const Size : DWORD): string;
const
  GB = 1024*1024*1024;
  MB = 1024*1024;
  KB = 1024;
begin
  if Size > GB then
    Result := Format('%%.2f GB', [Size / GB])
  else if Size > MB then
    Result := Format('%.2f MB', [Size / MB])
  else if Size > KB then
    Result := Format('%.2f KB', [Size / KB])
  else
    Result := Format('%d B', [Size]);
end;

 

posted on 2023-04-21 09:20  六十五度  阅读(41)  评论(0编辑  收藏  举报

导航