This is of course a purely syntactic operation on atoms (not strings, although strings are accepted). The module doesn't care whether the files or directories exist or not.
The character / is assumed special. The \ is NOT assumed special
Examples for mode (+Directory,+File,-Path)
:
?- directory_file_path("/alpha/beta","somefile",P). P = '/alpha/beta/somefile'. ?- directory_file_path("alpha/beta","somefile",P). P = 'alpha/beta/somefile'. ?- directory_file_path("alpha////beta","somefile",P). % cleanup not included P = 'alpha////beta/somefile'. ?- directory_file_path("alpha/beta/","somefile",P). P = 'alpha/beta/somefile'.
I'm not a fan of this. That should be cleaned up:
?- directory_file_path("alpha/beta///","somefile",P). P = 'alpha/beta///somefile'.
But this is ugly, if not buggy:
?- directory_file_path("alpha/beta/","/somefile",P). P = "/somefile".
Similarly:
?- directory_file_path("alpha/beta/","/somefile/someotherfile",P). P = "/somefile/someotherfile".
More edge cases:
?- directory_file_path("/","/somefile",P). P = "/somefile". ?- directory_file_path("","/somefile",P). P = "/somefile".
This is ugly:
?- directory_file_path("","somefile",P). P = '/somefile'.
Because here it's different:
?- directory_file_path("foo","somefile",P). P = 'foo/somefile'. ?- directory_file_path("foo/bar","somefile",P). P = 'foo/bar/somefile'.
Patterns for use in expand_file_name/2 can be created:
?- directory_file_path("alpha/beta","*.pl",P). P = 'alpha/beta/*.pl'.