Reputation: 16650
I would like to have a best prectice for this subject. I have to do some path magic prior to actually doing something.
using namespace boost::filesystem;
path p = "apple"; // apple
p /= "pear"; // apple/pear
p /= ".."; // apple/pear/.. // apple
p /= "chicken"; // apple/pear/../chicken // apple/chichken
p /= ".."; // apple/pear/../chicken/.. // apple
p /= ".."; // apple/pear/../chicken/../.. // .
p /= ".."; // apple/pear/../chicken/../../.. // ..
p /= "cow"; // apple/pear/../chicken/../../../cow // ../cow
path s = "\\tmp\\file857463.tmp"; // s.is_relative() is true on windows
In every line after the first //
you can see what I get when I print it. After the second //
you can see what I would like to see (if differs)
What intermediate step can/should I do if I would like to see this behavior, considering that I surely do not want to touch the filesystem. After the final form appears I would like to test that the reference points inside the current directory or not (still without accessing the FS).
I would like to detect upwards jumps like \
(windows) or \\
(windows) or /
on Linux. Quote from manual: On Windows, path("/foo").is_absolute() returns false. Which is IMHO very scientific, but useless. The main goal for me is to prevent upwards references without accessing characters by hand and without boost accessing the FS. (If I have to touch any characters manually I rather write my own path utility all together.)
I failed to find a robust concept for detecting drive root references. I tried boost documentation and Google too.
Upvotes: 1
Views: 2119
Reputation: 2713
Try to use canonical: http://www.boost.org/doc/libs/1_50_0/libs/filesystem/doc/reference.html#canonical
Upvotes: 1