Wie wäre es mit dieser Funktion:
Delphi-Quellcode:
function FileExists(
const Filename:
string): Boolean;
function FailSafe(
const Filename:
string): Boolean;
var
FindData: TWin32FindData;
h: THandle;
begin
{ Either the file is locked/share_exclusive or we got an access denied }
h := FindFirstFile(PChar(Filename), FindData);
if h <> 0
then
begin
Windows.FindClose(h);
Result := FindData.dwFileAttributes
and FILE_ATTRIBUTE_DIRECTORY = 0;
end
else
Result := False;
end;
var
Code: Integer;
LastError: Cardinal;
begin
Code := Integer(GetFileAttributes(Pointer(FileName)));
if Code <> -1
then
Result := (FILE_ATTRIBUTE_DIRECTORY
and Code = 0)
else
begin
LastError := GetLastError();
Result := (LastError <> ERROR_FILE_NOT_FOUND)
and
(LastError <> ERROR_PATH_NOT_FOUND)
and
FailSafe(Filename);
end;
end;