Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h3>Boost v1.48 and above</h3> <p>You can use <code>boost::filesystem::canonical</code>:</p> <pre><code>path canonical(const path&amp; p, const path&amp; base = current_path()); path canonical(const path&amp; p, system::error_code&amp; ec); path canonical(const path&amp; p, const path&amp; base, system::error_code&amp; ec); </code></pre> <p><a href="http://www.boost.org/doc/libs/1_48_0/libs/filesystem/v3/doc/reference.html#canonical" rel="noreferrer">http://www.boost.org/doc/libs/1_48_0/libs/filesystem/v3/doc/reference.html#canonical</a></p> <p>v1.48 and above also provide the <code>boost::filesystem::read_symlink</code> function for resolving symbolic links.</p> <h3>Boost versions prior to v1.48</h3> <p>As mentioned in other answers, you can't normalise because boost::filesystem can't follow symbolic links. However, you can write a function that normalises "as much as possible" (assuming "." and ".." are treated normally) because boost offers the ability to determine whether or not a file is a symbolic link.</p> <p>That is to say, if the parent of the ".." is a symbolic link then you have to retain it, otherwise it is probably safe to drop it and it's probably always safe to remove ".".</p> <p>It's similar to manipulating the actual string, but slightly more elegant.</p> <pre><code>boost::filesystem::path resolve( const boost::filesystem::path&amp; p, const boost::filesystem::path&amp; base = boost::filesystem::current_path()) { boost::filesystem::path abs_p = boost::filesystem::absolute(p,base); boost::filesystem::path result; for(boost::filesystem::path::iterator it=abs_p.begin(); it!=abs_p.end(); ++it) { if(*it == "..") { // /a/b/.. is not necessarily /a if b is a symbolic link if(boost::filesystem::is_symlink(result) ) result /= *it; // /a/b/../.. is not /a/b/.. under most circumstances // We can end up with ..s in our result because of symbolic links else if(result.filename() == "..") result /= *it; // Otherwise it should be safe to resolve the parent else result = result.parent_path(); } else if(*it == ".") { // Ignore } else { // Just cat other path entries result /= *it; } } return result; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload