| Technical Specification | ||||
| Filesystem library(filesystem TS) | ||||
| Library fundamentals(library fundamentals TS) | ||||
| Library fundamentals 2(library fundamentals TS v2) | ||||
| Library fundamentals 3(library fundamentals TS v3) | ||||
| Extensions for parallelism(parallelism TS) | ||||
| Extensions for parallelism 2(parallelism TS v2) | ||||
| Extensions for concurrency(concurrency TS) | ||||
| Extensions for concurrency 2(concurrency TS v2) | ||||
| Concepts(concepts TS) | ||||
| Ranges(ranges TS) | ||||
| Reflection(reflection TS) | ||||
| Mathematical special functions(special functions TR) | ||||
| Experimental Non-TS | ||||
| Pattern Matching | ||||
| Linear Algebra | ||||
| std::execution | ||||
| Contracts | ||||
| 2D Graphics |
| Classes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| File types | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Defined in header <experimental/filesystem> | ||
path canonical(const path& p,const path& base= current_path()); | (1) | (filesystem TS) |
path canonical(const path& p, error_code& ec); | (2) | (filesystem TS) |
path canonical(const path& p,const path& base, error_code& ec); | (3) | (filesystem TS) |
Converts pathp to a canonical absolute path, i.e. an absolute path that has no dot, dot-dot elements or symbolic links.
Ifp is not an absolute path, the function behaves as if it is first made absolute byabsolute(p, base) orabsolute(p) for(2).
The pathp must exist.
Contents |
| p | - | a path which may be absolute or relative tobase, and which must be an existing path |
| base | - | base path to be used in casep is relative |
| ec | - | error code to store error status to |
An absolute path that resolves to the same file asabsolute(p, base) (orabsolute(p) for(2)).
This function is modeled after the POSIXrealpath.
#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';}
Possible output:
Current path is "C:\Users\abcdef\AppData\Local\Temp"Canonical path for "..\..\AppData" is "C:\Users\abcdef\AppData"
| represents a path (class)[edit] | |
| composes an absolute path converts a path to an absolute path replicating OS-specific behavior (function)[edit] |