27 Input/output library [input.output]

27.10 File systems [filesystems]

27.10.8 Class path [class.path]

27.10.8.4 path members [path.member]

27.10.8.4.9 path decomposition [path.decompose]

path root_name() const;

Returns: root-name, if pathstring includes root-name, otherwise path().

path root_directory() const;

Returns: root-directory, if pathstring includes root-directory, otherwise path().

path root_path() const;

Returns: root_name() / root_directory().

path relative_path() const;

Returns: A path composed from pathstring, if !empty(), beginning with the first filename after root-path. Otherwise, path().

path parent_path() const;

Returns: (empty() || begin() == --end()) ? path() : pp, where pp is constructed as if by starting with an empty path and successively applying operator/= for each element in the range [begin(), --end()).

path filename() const;

Returns: empty() ? path() : *--end().

Example:

std::cout << path("/foo/bar.txt").filename(); // outputs "bar.txt"
std::cout << path("/").filename();            // outputs "/"
std::cout << path(".").filename();            // outputs "."
std::cout << path("..").filename();           // outputs ".."

 — end example ]

path stem() const;

Returns: if filename() contains a period but does not consist solely of one or two periods, returns the substring of filename() starting at its beginning and ending with the character before the last period. Otherwise, returns filename().

Example:

std::cout << path("/foo/bar.txt").stem(); // outputs "bar"
path p = "foo.bar.baz.tar";
for (; !p.extension().empty(); p = p.stem())
  std::cout << p.extension() << '\n';
  // outputs: .tar
  //          .baz
  //          .bar

 — end example ]

path extension() const;

Returns: if filename() contains a period but does not consist solely of one or two periods, returns the substring of filename() starting at the rightmost period and for the remainder of the path. Otherwise, returns an empty path object.

Remarks: Implementations are permitted to define additional behavior for file systems which append additional elements to extensions, such as alternate data streams or partitioned dataset names.

Example:

std::cout << path("/foo/bar.txt").extension(); // outputs ".txt"

 — end example ]

Note: The period is included in the return value so that it is possible to distinguish between no extension and an empty extension. Also note that for a path p, p.stem()+p.extension() == p.filename().  — end note ]