Files
cppdraft_translate/cppdraft/fs/path/decompose.md
2025-10-25 03:02:53 +03:00

5.4 KiB

[fs.path.decompose]

31 Input/output library [input.output]

31.12 File systems [filesystems]

31.12.6 Class path [fs.class.path]

31.12.6.5 Members [fs.path.member]

31.12.6.5.9 Decomposition [fs.path.decompose]

🔗

path root_name() const;

1

#

Returns: root-name, if the pathname in the generic format includes root-name, otherwise path().

🔗

path root_directory() const;

2

#

Returns: root-directory, if the pathname in the generic format includes root-directory, otherwise path().

🔗

path root_path() const;

3

#

Returns: root_name() / root_directory().

🔗

path relative_path() const;

4

#

Returns: A path composed from the pathname in the generic format, if empty() is false, beginning with the first filename after root_path().

Otherwise, path().

🔗

path parent_path() const;

5

#

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.

🔗

path filename() const;

6

#

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

7

#

[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]

🔗

path stem() const;

8

#

Returns: Let f be the generic format pathname of filename().

Returns a path whose pathname in the generic format is

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

otherwise, the prefix of f ending before its last period.

9

#

[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]

🔗

path extension() const;

10

#

Returns: A path whose pathname in the generic format is the suffix of filename() not included in stem().

11

#

[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

#

[Note 1:

The period is included in the return value so that it is possible to distinguish between no extension and an empty extension.

— end note]

13

#

[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.

— end note]