如何测试文件是否为空

Dau*_*evy 1 delphi

我想检查文件是否存在以及是否存在是否为空。

我可以处理文件是否存在;

if FileExists(fileName) then

else
   ShowMessage('File Not Exists');
Run Code Online (Sandbox Code Playgroud)

如何测试一个空文件?

LU *_* RD 6

如@TLama建议的,如果找到文件且大小为零,则以下函数返回true。

function FileIsEmpty(const FileName: String): Boolean;
var
  fad: TWin32FileAttributeData;
begin
  Result := GetFileAttributesEx(PChar(FileName), GetFileExInfoStandard, @fad) and
            (fad.nFileSizeLow = 0) and (fad.nFileSizeHigh = 0);
end;
Run Code Online (Sandbox Code Playgroud)