scryer-prolog icon indicating copy to clipboard operation
scryer-prolog copied to clipboard

directory_exists/2 does not normalize path

Open rotu opened this issue 8 months ago • 0 comments

On Windows, it's surprising that directory_exists/2 doesn't seem to normalize away the path delimiter tokens .. and .. It also does not coalesce redundant /. This also happens for path_canonical/2.

?- use_module(library(files))
   true.
?- directory_exists("\\\\?\\C:\\Windows").
   true.
?- directory_exists("\\\\?\\C:\\Windows\\").
   true.
?- directory_exists("\\\\?\\C:\\Windows\\\\").
   false.
?- directory_exists("\\\\?\\C:\\Windows\\.").
   false.
?- path_canonical("\\\\?\\C:\\Windows\\.",X).
   false.

Also relevant it seems to me path_canonical/2 is named slightly misleadingly. I would expect it to perform the syntactic operation of normalizing a path, irrespective of the file it points at or whether a file exists. But instead it operates on files, resolving an absolute path according to the current state of the filesystem. I might expect it be called file_resolve/2 instead or absolute_file_name/2 as in SWI and SICStus.

rotu avatar May 02 '25 23:05 rotu