Delphi directoryexists performs odd behavior for network mappings

In delphi XE, when I call the SysUtils DirectoryExists function with the following input

'Y: \ blabla \'

where Y is the network mapped block, it correctly returns false because blabla does not exist.

But when I call with the next input

'Y: \ blably \ Y: \ l

it returns true.

The documentation is bad and I have not found anywhere in the environment of people with the same problem

Perhaps someone here already had this problem, or do you know what is happening?

+5
source share
2 answers

There seems to be a bug in the implementation of DirectoryExists .

This is the corresponding code for this function.

function DirectoryExists(const Directory: string; FollowLink: Boolean = True): Boolean;
{$IFDEF MSWINDOWS}
var
  Code: Cardinal;
  Handle: THandle;
  LastError: Cardinal;
begin
  Result := False;
  Code := GetFileAttributes(PChar(Directory));

  if Code <> INVALID_FILE_ATTRIBUTES then
  begin
    ...
    //more code
    ...
  end
  else
  begin
    LastError := GetLastError;
    Result := (LastError <> ERROR_FILE_NOT_FOUND) and
      (LastError <> ERROR_PATH_NOT_FOUND) and
      (LastError <> ERROR_INVALID_NAME) and
      (LastError <> ERROR_BAD_NETPATH);
  end;
end;
{$ENDIF MSWINDOWS}

, GetFileAttributes, GetLastError . ERROR_BAD_PATHNAME (161), True.

+5

XE8 (, , ). RRUZ, SysUtils BOTH DirectoryExists() TDirectory.Exists().

, "" , , INVALID_FILE_ATTRIBUTES "" . , , , , , . INVALID_FILE_ATTRIBUTES , . , , , . , , . , - , ", , ", , , / : , 99,9% , INVALID_FILE_ATTRIBUTES , , TRUE , .

, , , , " " - , , -: , , , "", ! GetLastError, .

, - Sysutils.DirectoryExists ( , ) TDirectory.Exists , . :

DirectoryUsable(const Directory: string; FollowLink: Boolean = True): Boolean;
begin
   Result := GetFileAttributes(PChar(Directory)) <> INVALID_FILE_ATTRIBUTES;
   if Result then Result := DirectoryExists( Directory, FollowLink );
end;

, "" , , Embarcadero - , . , .

SysUtils, , Delphi , . , , " " . , , " ". , TRUE.

0

All Articles