Delphi 获取文件大小根据显示GB MB KB B


本文整理自网络,侵删。

 
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;
 
function GetFileSizeStr(const FileName : string): string;
var
  Size: DWORD;
begin
  Size := GetFileSize(FileName);
  Result :=CalcFileSizeStr(Size);
end;

相关阅读 >>

Delphi webbrowser1 execwb 复制 新建 打开

Delphi 62 进制的简单实现

Delphi如何获取硬盘所有的分区容量

Delphi comparedatetime、comparedate、comparetime、samedatetime、samedate、sametime �c 对比时间的函数

Delphi复制整个文件夹(当然包括嵌套文件夹)

Delphi 锁定鼠标移动范围

Delphi thttpclient 时获取跳转后的 url

Delphi 脉搏波9808血压计读取测试程序

Delphi uhttp_flood

Delphi firemonkey的stylebook皮肤控件的使用

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...