isAnsi/de
Zurück zur Seite Code Beispiele.
Das Unterprogramm prüft, unabhängig vom zugrunde liegenden Betriebssystem, ob es sich um eine ANSI-Datei handelt.
Mit dieser Methode werden auch ASCII-Dateien als ANSI-Dateien erkannt.
Eine 100 prozentige Methode, eine Textdatei zweifelsfrei als ANSI-Datei zu erkennen, gibt es nicht.
uses
FileUtil, ...;
...
function isAnsi(const conStrQuellDateiname: string): boolean;
var
txtQuelldatei: file of char;
chrZeichen: char;
begin
Result := False;
AssignFile(txtQuelldatei, UTF8ToSys(conStrQuellDateiname));
Reset(txtQuelldatei);
while not EOF(txtQuelldatei) do
begin
Read(txtQuelldatei, chrZeichen);
if (chrZeichen < #32) and (not (chrZeichen in [#9, #10, #13, #26])) then
begin
closefile(txtQuelldatei);
exit;
end;
end;
Result := True;
closefile(txtQuelldatei);
end;Aufruf unter Windows:
...
if isAnsi('E:\Test.txt') = True then
...
...Aufruf unter Linux:
...
if isAnsi('/home/user/Test.txt') = True then
...
...From the Free Pascal wiki, page "isAnsi/de", as it stood on 2020-02-18 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.