Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check whether two paths are to the same file/directory with Boost.Filesystem

Tags:

c++

boost

I want to check whether two paths are to the same file/directory with Boost.Filesystem.

For example, "/bin" and "/./bin" are to the same directory, but the following code doesn't work as intended.

namespace fs = boost::filesystem;
fs::path p1{"/bin"}, p2{"/./bin"};

if(p1 == p2){
    std::cout << "Equal" << std::endl;
}else{
    std::cout << "Not equal" << std::endl;
}

The output of this is "Not equal".

How can I check whether two paths are to the same file/directory? Could you tell me this?

Thanks.

like image 528
Tsuzu Avatar asked Jan 07 '23 16:01

Tsuzu


1 Answers

You should use equivalent function, since comparison operators for paths compare only lexicographical order.

like image 94
ForEveR Avatar answered Feb 01 '23 15:02

ForEveR