function RTL_MOD_FileExists(
const FileName:
String): Boolean;
var
Handle: THandle;
FindData: TWin32FindData;
begin
Result := False;
Handle := Windows.FindFirstFile(PChar(FileName), FindData);
if Handle <> INVALID_HANDLE_VALUE
then
begin
Result := ( (FindData.dwFileAttributes
and FILE_ATTRIBUTE_DIRECTORY) = 0 );
Windows.FindClose(
Handle);
end;
end;
function jgbFileExists(
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 := Windows.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(Windows.GetFileAttributes(Pointer(FileName)));
if Code <> -1
then
Result := (FILE_ATTRIBUTE_DIRECTORY
and Code = 0)
else
begin
LastError := Windows.GetLastError();
Result := (LastError <> ERROR_FILE_NOT_FOUND)
and
(LastError <> ERROR_PATH_NOT_FOUND)
and
FailSafe(Filename);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var b: Boolean;
i: Integer;
Start: Cardinal;
s, FileName:
String;
begin
i := 0;
Start := Windows.GetTickCount;
//FileName := 'C:\pagefile.sys';
FileName := '
C:\boot.ini';
repeat
//b := jgbFileExists(FileName);
b := MyFileExists(FileName);
inc(i);
until (i > 100000);
if b
then
s := '
True'
else
s := '
False';
ShowMessage( IntToStr(Windows.GetTickCount - Start) + '
ms' + #13#10 + s);
end;