I am trying to display a network share path in my Prolog output code.
The path is like :
\\fileserver\path\to\file.txt (ex1)
or
\\\\fileserver\\path\\to\\file.txt (ex2)
but If I try displaying it using format :
pri(Z):-
format('Printing Zx : \"~w\"',[Z]).
the slashes get truncated to
\fileserverpathtofile.txt (ex1)
Obviously some times, the path may contain \\\\ in which case the display is correct.
How to make it print proper path?
Any help please.
Thanks.
In the Prolog atoms backslash is a meta-character, i.e. if you want your atom to contain a backslash character then you need to escape it using the backslash character. E.g. in order to represent the Windows path
\\fileserver\path\to\file.txtas a Prolog atom you need to writeIn principle there are two ways of printing stuff out, one for the humans (pretty-printing), using
writeand one for the machines (serializing), using
write_canonicalwrite_canonicalmakes sure that Prolog can read the output back into the same exact atom.Your problem seems to be that you do not correctly represent the path in Prolog. If the path comes from an external source, you first need to escape it (add a backslash in front of every backslash) before you can store it as a Prolog atom.