Reputation: 47
How to convert a boost::filesystem::path in a form of:
root/subdir1/subdir2/../some.file
to:
root/subdir1/some.file
with possibly multiple "go level up" operators?
Upvotes: 2
Views: 1579
Reputation: 21
Why not use the branch_path() ? It returns the parent directory of a boost::filesystem::path
Example:
boost::filesystem::path path("root/subdir1/subdir2/some.file");
boost::filesystem::path parent = path.branch_path().branch_path(); // "root/subdir1"
boost::filesystem::copy(path, parent);
boost::filesystem::remove(path.branch_path());
You can use it whatever you like.
Upvotes: 1
Reputation: 24576
Short question, short answer:
By subsequently simply erasing every /<dirname>/..
occurence from the path. You could easily use regex for that.
Upvotes: 1