A
A
andreloster2014-11-16 22:32:32
Delphi
andreloster, 2014-11-16 22:32:32

How to check if a file is empty in Delphi?

Greetings.
There was a need to make a condition for checking the .txt text file for emptiness (there is nothing there, including whitespace characters, line feeds, carriage returns, etc.). Did an existence check.
I will be grateful.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mercury13, 2014-11-16
@andreloster

type
  TFileState = ( fsMissing, fsEmpty, fsSomething );

function GetFileState(s : string) : TFileState;
var
  sr : TSearchRec;
  err : integer;
begin
  err := FindFirst(s, faAnyFile and not faDirectory, sr);
  if err <> 0
    then Result := fsMissing
  else if sr.Size = 0
    then Result := fsEmpty
    else Result := fsSomething;
  FindClose(sr);
end;

B
BladgeR, 2014-11-16
@BladgeR

check file for emptiness

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question