Autor Beitrag
moloch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 451

Win 2000
D5 Prof
BeitragVerfasst: Fr 15.10.04 15:35 
hallo leute,
wie mache ich am besten einen Lese-test auf ein bestimmtes verzeichnis oder datei.

mfg
moloch


Moderiert von user profile iconChristian S.: Topic aus CLX / Delphi Language (Object-Pascal) verschoben am Fr 15.10.2004 um 17:03
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 15.10.04 15:48 
Da muss ich dir doch schon wieder die gleichen Antworten geben. :wink:
1. Mit FileExists kanns du prüfen, ob die Datei überhaupt da ist.
2. AssignFile, Reset und IOResult helfen dir dann festzustellen, ob die Datei lesbar ist. Nicht vergessen CloseFile zu benutzen, wenn das reset erfolgreich war. Sonst sperrst du die Datei am Ende noch selbst.
moloch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 451

Win 2000
D5 Prof
BeitragVerfasst: Fr 15.10.04 16:04 
hey,
dank dir noch mal.
ich habs jetzt auch schon so gemacht mit assignfile.
wollt nur wissen ob es was "besseres" oder anderes gibt.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
  result := True;

  sDatei := sH + cTest;
  if FileAppend(sDatei, 'Das ist ein LeseTest.') then begin
    try
      AssignFile(f, sDatei);
      try
        Reset(f);
      finally
        CloseFile(f);
        Sysutils.deletefile(sDatei);
      end;
    except
      result := False;
      Sysutils.deletefile(sDatei);
    end;
  end;



mfg
moloch
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 15.10.04 16:10 
Wenns dir darum geht eine vorhandene Datei zu löschen, genügt DeleteFile. Im Fehlerfall gibt dir die Funktion False zurück.
Da brauchst du kein Assignfile oder sonstwas.