In delphi XE, when I call SysUtils DirectoryExists function with the following input
'Y:\blabla\'
where Y is a network mapped unit, it correctly returns false because blabla doesnt exist.
But when I call with the following input
'Y:\blabla\Y:\bla'
it returns true.
Documentation is poor, and I've not found anywhere on the internets people with the same problem
maybe someone here already had this problem, or know what is happening?
It seems a bug in the implementation of the DirectoryExists function.
This is the relevant code of 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}
As you see if the GetFileAttributes
function call fails, the result of the GetLastError
method is compared against a set of possible values. but in your case passing a invalid path will return a ERROR_BAD_PATHNAME
(161) code, so the function returns True.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With