[fpc-pascal]SysUtils.FileExists bug under Go32v2

Iván Montes senbei at terra.es
Wed Feb 12 20:28:27 CET 2003


Hi,

I think I've found a bug on the FileExists function (sysutils) under Go32v2,
when I want to check if a directory exists.

FileExists( 'c:\winnt' ) will return False when compiled for Go32 but true
for Win32.
I guess that the Win32 version is doing rigth, since a directory is part of
the file system.

I've checked a recent CVS copy of the sources and I found this

[go32v2/sysutls.pp]

Function FileExists (Const FileName : String) : Boolean;
var Handle: longint;
begin
  //!!   This can be done quicker, need to find out how
  Result := (OpenFile(FileName, Handle, ofRead, faOpen) = 0);
  if Handle <> 0 then
    FileClose(Handle);
end;

this could be changed for example to:

Function FileExists (Const filename :String) :Boolean;
begin
   //FileGetAttrib will return -1 if the file was not found
   //but I don't know if it will return -1 if the file exists but it's open
   result := boolean( FileGetAttr( filename ) XOR -1 );
end;

hope this helps,
Ivan




More information about the fpc-pascal mailing list