[fs.path.decompose]

# 31 Input/output library [[input.output]](./#input.output)

## 31.12 File systems [[filesystems]](filesystems#fs.path.decompose)

### 31.12.6 Class path [[fs.class.path]](fs.class.path#fs.path.decompose)

#### 31.12.6.5 Members [[fs.path.member]](fs.path.member#fs.path.decompose)

#### 31.12.6.5.9 Decomposition [fs.path.decompose]

[ð](#lib:root_name,path)

`path root_name() const;
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L14859)

*Returns*: [*root-name*](fs.path.generic#nt:root-name "31.12.6.2 Generic pathname format [fs.path.generic]"), if the pathname in the generic format
includes [*root-name*](fs.path.generic#nt:root-name "31.12.6.2 Generic pathname format [fs.path.generic]"), otherwise path()[.](#1.sentence-1)

[ð](#lib:root_directory,path)

`path root_directory() const;
`

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L14871)

*Returns*: [*root-directory*](fs.path.generic#nt:root-directory "31.12.6.2 Generic pathname format [fs.path.generic]"), if the pathname in the generic format
includes [*root-directory*](fs.path.generic#nt:root-directory "31.12.6.2 Generic pathname format [fs.path.generic]"), otherwise path()[.](#2.sentence-1)

[ð](#lib:root_path,path)

`path root_path() const;
`

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L14883)

*Returns*: root_name() / root_directory()[.](#3.sentence-1)

[ð](#lib:relative_path,path)

`path relative_path() const;
`

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L14894)

*Returns*: A path composed from the pathname in the generic format,
if empty() is false, beginning
with the first [*filename*](fs.path.generic#nt:filename "31.12.6.2 Generic pathname format [fs.path.generic]") after root_path()[.](#4.sentence-1)

Otherwise, path()[.](#4.sentence-2)

[ð](#lib:parent_path,path)

`path parent_path() const;
`

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L14907)

*Returns*: *this if has_relative_path() is false,
otherwise a path whose generic format pathname is
the longest prefix of the generic format pathname of *this that produces one fewer element in its iteration[.](#5.sentence-1)

[ð](#lib:filename,path)

`path filename() const;
`

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L14921)

*Returns*: relative_path().empty() ? path() : *--end()[.](#6.sentence-1)

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L14925)

[*Example [1](#example-1)*: path("/foo/bar.txt").filename(); // yields "bar.txt" path("/foo/bar").filename(); // yields "bar" path("/foo/bar/").filename(); // yields "" path("/").filename(); // yields "" path("//host").filename(); // yields "" path(".").filename(); // yields "." path("..").filename(); // yields ".." â *end example*]

[ð](#lib:stem,path)

`path stem() const;
`

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L14945)

*Returns*: Let f be the generic format pathname of filename()[.](#8.sentence-1)

Returns a path whose pathname in the generic format is

- [(8.1)](#8.1)

f, if it contains no periods other than a leading period
or consists solely of one or two periods;

- [(8.2)](#8.2)

otherwise, the prefix of f ending before its last period[.](#8.sentence-2)

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L14955)

[*Example [2](#example-2)*: 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*]

[ð](#lib:extension,path)

`path extension() const;
`

[10](#10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L14975)

*Returns*: A path whose pathname in the generic format is
the suffix of filename() not included in stem()[.](#10.sentence-1)

[11](#11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L14980)

[*Example [3](#example-3)*: path("/foo/bar.txt").extension(); // yields ".txt" and stem() is "bar" path("/foo/bar").extension(); // yields "" and stem() is "bar" path("/foo/.profile").extension(); // yields "" and stem() is ".profile" path(".bar").extension(); // yields "" and stem() is ".bar" path("..bar").extension(); // yields ".bar" and stem() is "." â *end example*]

[12](#12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L14991)

[*Note [1](#note-1)*:

The period is included in the return value so that it is
 possible to distinguish between no extension and an empty extension[.](#12.sentence-1)

â *end note*]

[13](#13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L14997)

[*Note [2](#note-2)*:

On non-POSIX operating systems, for a path p,
it is possible that p.stem() + p.extension() == p.filename() is false,
even though the generic format pathnames are the same[.](#13.sentence-1)

â *end note*]
