Einzelnen Beitrag anzeigen

Bjoerk

Registriert seit: 28. Feb 2011
Ort: Mannheim
1.384 Beiträge
 
Delphi 10.4 Sydney
 
#13

AW: FileHasTextFormat?

  Alt 1. Mär 2012, 09:25
Hab's in meiner Sammlung jetzt erst mal so drin.

Gruß
Thomas

Delphi-Quellcode:
function IsProbablyTextfile(const FileName: string): boolean;
var
  S : string; // AnsiString
  F : TFileStream;
  I,R : Integer;
begin
  Result:= false;
  if not FileExists(FileName) then Exit;
  F:= TFileStream.Create(FileName, fmOpenRead);
  try
    if F.Size > 0 then
    try
      Result:= true;
      if F.Size > MaxInt then
        R:= MaxInt
      else
        R:= F.Size;
      SetLength(S, R);
      F.Read(S[1], R);
      for I:= 1 to R do
        if (S[I] < #32) and (not (S[I] in [#9, #10, #13, #26])) then
        begin
          Result:= false;
          Break;
        end;
    except
      Result:= false;
    end;
  finally
    F.free;
  end;
end;

Geändert von Bjoerk ( 1. Mär 2012 um 10:35 Uhr) Grund: Prüfung aus Size > Null
  Mit Zitat antworten Zitat