如何判断一个文件为空?有哪些函数可以用?
解决方案 »
- 自己构造ADODataSet数据集
- 今天收到用C币换购邮寄来的新书,开心散分!
- 请问 如何获得正在使用的控件名? 正在执行的程序的信息?
- 帮小弟一把!!!
- 请大侠们推荐个打印预览控件(拜托各位)
- 如何用BDE配置ODBC,谢谢?
- 关于控件安装的问题!!!!!!!!
- Delphi如何调用VC写的DLL,(如何通过传递地址方式来调用VC写的Function?)有点麻烦!
- 请问动态库中的函数参数中如果有回调函数的应该怎么调用?
- 老千,你在哪里??偶用setrange除了故障(牛虻)
- 5个回复以后就不要来了,重复的不算哦:)
- adoquery通过odbc连接sql_server,网络中断后,如何自己回复连接?
MyFile: File of Byte;
begin
//如果文件存在
if FileExists('d:\test.txt') then
begin
try
//建立文件关联
AssignFile(MyFile,'d:\test.txt');
//打开文件
Reset(MyFile);
if FileSize(MyFile)=0 then
Showmessage('it is empty')
else Showmessage('it is not empty');
finally
//无论如何,关闭文件
CloseFile(MyFile);
end; //end of try
end; //end of if
end;
-------------
var
aFileStream:TFileStream;
FileName:string;
begin
FileName:='F:\1.txt';
if FileExists(FileName) then
aFileStream:=TFileStream.Create(FileName,fmOpenRead);
try
if aFileStream.Size=0 then
ShowMessage('文件为空');
finally
aFileStream.Free;
end;
end;
begin
result := -1;
if not FileExists(sFileName) then exit;
with TFileStream.Create(sFileName, fmOpenRead) do begin
try
result := size;
finally
free;
end;
end;
end;