Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   FileHasTextFormat? (https://www.delphipraxis.net/166799-filehastextformat.html)

Bjoerk 29. Feb 2012 23:51

AW: FileHasFextFormat?
 
Ja, sehe ich aus so. bat, ini, rc, xml, pas, htm, html, txt, rtf sind für mich auch Textdateien.

Edit: Vielleicht schenke ich mir das ganze auch und prüfe nur die Extension.

Edit2: die pas History Files haben scheinbar ein #>=127 irgendwo, hab ich eben mal getestet.

Luckie 1. Mär 2012 07:25

AW: FileHasFextFormat?
 
@Bjoerk: Wenn du schon gemerkt hast, dass du dich vertippt hast, könntest du es dann bitte noch korrigieren, sowohl im Beitrag, als auch im Titel?

Bjoerk 1. Mär 2012 09:25

AW: FileHasTextFormat?
 
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;

himitsu 1. Mär 2012 09:38

AW: FileHasTextFormat?
 
Wozu eigentlich die 26/$1A.

Das ist ja im Prinzip auch kein gültiges Zeichen.
Offiziell wäre es das Ersatzzeichen, für nicht umwandlungsfähige Zeichen (nach der Umwandlung), wobei Windows dafür standardäßig allerdings das ? nutzt, da das Andere oftmals keinen sichtbaren Gegenpart hat, in dem meisten Fonts.

Bjoerk 1. Mär 2012 10:02

AW: FileHasTextFormat?
 
# 26 = Substitute (End Of Text File)

Kann man sich vermutlich aber schenken.

himitsu 1. Mär 2012 10:13

AW: FileHasTextFormat?
 
Kommt drauf an, die TStringList nimmt die #0 als Ende, da die WinAPI mit PChar arbeitet und im Memo es dort dann auch enden würde.


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:02 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz