5

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.

1 Answer 1

10

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

1
  • Thank you! That's just what I has wanted.
    – Tsuzu
    Aug 31, 2015 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.