The documentation of boost::filesystem::path::lexically_normal()
states:
Returns
*this
with redundant current directory (dot), parent directory (dot-dot), and directory-separator elements removed.
See: http://www.boost.org/doc/libs/1_63_0/libs/filesystem/doc/reference.html.
The following prints ./test
(using Boost 1.63.0) where I would expect test
:
#include <boost/filesystem/path.hpp>
#include <iostream>
int main(void)
{
std::cout << boost::filesystem::path{"./test"}.lexically_normal().string() << "\n";
return 0;
}
So the first dot element is not considered redundant. However, both test
and ./test
obviously resolve to the same file when using boost filesystem, so this seems inconsistent to me. Is this expected behavior?
Update: the C++17 filesystem library returns "test"
as expected (GCC 8.2.0, Linux).
It is reasonable behaviour, because although you are right that test
and ./test
usually refer to the same thing, this is not the case everywhere.
For example, if you run ./test
as a command in a shell, it will always look for that program in the current directory and nowhere else. But if you run test
it will look in the runtime path (e.g. $PATH
) instead.
So whether test
and ./test
refer to the same file is actually context dependent--therefore the ./
is not redundant.
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