Autor Beitrag
Biarchiv
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 688



BeitragVerfasst: So 03.07.05 09:20 
Hey,

ich suche eine function damit ich prüfen kann ob Dateien vorhanden oder nicht sind.
Allerdings schreibe ich eine kleine File und solte ohne sysutils gehen.

Gibts vieleicht eine API oder so?
maxk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: So 03.07.05 09:27 
Naja, ich habe das damals in TP immer so realisiert (auf Delphi portiert):
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
function FileExists(const FileName:string):boolean;
var f:File;
begin
 {$I-}
 Assign(f, FileName);
 Reset(f);
 Close(f);
 {$I+}
 Result:=IOResult=0;
end;


Das prüft allerdings mehr auf Lesbarkeit als auf Existens, aber was besseres wäre mir erstmal nicht bekannt (jedenfalls nicht mit Hausmitteln).

Gruß,
maxk


// Edit: An Suche im MSDN CREATEFILE hatte ich jetzt gar nicht gedacht :oops:

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 03.07.05 09:40 
Wenn man im Forum ein bisschen nach Suche in: Delphi-Forum, Delphi-Library FILEEXISTS sucht, findet man auch die API-Variante. Unter anderem habe ich sie gepostet, und das war (laut Forum) vor einem Jahr.
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: So 03.07.05 10:01 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
function FileExists(const FileName: String): Boolean;
var
  Handle: THandle;
  FindData: TWin32FindData;
begin

  Result := False;
  Handle := FindFirstFile(PChar(FileName), FindData);
  if Handle <> INVALID_HANDLE_VALUE then
  begin
    if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
      Result := True;
    Windows.FindClose(Handle);
  end;

end;

_________________
Ciao, Sprint.
maxk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: So 03.07.05 10:20 
Das ist natürlich besser :lol:

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.