std::experimental::filesystem::canonical

Header: <experimental/filesystem>

Converts path p to a canonical absolute path, i.e. an absolute path that has no dot, dot-dot elements or symbolic links.

# Declarations

path canonical( const path& p, const path& base = current_path() );

(filesystem TS)

path canonical( const path& p, error_code& ec );

(filesystem TS)

path canonical( const path& p, const path& base, error_code& ec );

(filesystem TS)

# Parameters

# Return value

An absolute path that resolves to the same file as absolute(p, base) (or absolute(p) for (2)).

# Example

#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
 
int main()
{
    fs::path p = fs::path("..") / ".." / "AppData";
    std::cout << "Current path is " << fs::current_path() << '\n'
              << "Canonical path for " << p << " is " << fs::canonical(p) << '\n';
}

# See also