Delphi判断文件大小


本文整理自网络,侵删。

 Delphi判断文件大小

Delphi自身提供了FileSize函数,例如:
var
f: file of Byte;
size : Longint;
begin
AssignFile(f, 'f:\t.exe');
Reset(f);
size := FileSize(f);
edit1.text := IntToStr(size);
CloseFile(f);
end;
这一种如果判断的文件被其它程序使用,则会报错 I/O Error



下面这种方法相对更好一些
也可以使用下面的方法:
function GetFileSize(const FileName: String): LongInt;
var SearchRec: TSearchRec;
begin
if FindFirst(ExpandFileName(FileName), faAnyFile, SearchRec) = 0 then
Result := SearchRec.Size
else
Result := -1;
end;

相关阅读 >>

Delphi使用idhttp 获取 httpsurl内容

Delphi xe10.1 andriod app中文名称

Delphi 文件分割合并

Delphi得到cpu的序列号

Delphi webbrowser1 保存文档为 .html

Delphi gethomepath - 获取用户程序数据目录

vclzip控件的简单使用

Delphi stringtowidestring widestringtostring

Delphi编程防止界面卡死的方法

Delphi 如何得到动态链接库的输出函数tdump命令

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



打赏

取消

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

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

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

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

评论

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