[fs.path.modifiers]

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

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

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

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

#### 31.12.6.5.5 Modifiers [fs.path.modifiers]

[ð](#lib:clear,path)

`void clear() noexcept;
`

[1](#1)

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

*Postconditions*: empty() is true[.](#1.sentence-1)

[ð](#lib:make_preferred,path)

`path& make_preferred();
`

[2](#2)

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

*Effects*: Each [*directory-separator*](fs.path.generic#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]") of the pathname in the generic format
is converted to [*preferred-separator*](fs.path.generic#nt:preferred-separator "31.12.6.2 Generic pathname format [fs.path.generic]")[.](#2.sentence-1)

[3](#3)

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

*Returns*: *this[.](#3.sentence-1)

[4](#4)

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

[*Example [1](#example-1)*: path p("foo/bar");
std::cout << p << '\n';
p.make_preferred();
std::cout << p << '\n';

On an operating system where [*preferred-separator*](fs.path.generic#nt:preferred-separator "31.12.6.2 Generic pathname format [fs.path.generic]") is a slash,
the output is:"foo/bar""foo/bar"

On an operating system where [*preferred-separator*](fs.path.generic#nt:preferred-separator "31.12.6.2 Generic pathname format [fs.path.generic]") is a backslash, the
output is:"foo/bar""foo\bar"

â *end example*]

[ð](#lib:remove_filename,path)

`path& remove_filename();
`

[5](#5)

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

*Effects*: Remove the generic format pathname of filename() from the generic format pathname[.](#5.sentence-1)

[6](#6)

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

*Postconditions*: !has_filename()[.](#6.sentence-1)

[7](#7)

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

*Returns*: *this[.](#7.sentence-1)

[8](#8)

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

[*Example [2](#example-2)*: path("foo/bar").remove_filename(); // yields "foo/" path("foo/").remove_filename(); // yields "foo/" path("/foo").remove_filename(); // yields "/" path("/").remove_filename(); // yields "/" â *end example*]

[ð](#lib:replace_filename,path)

`path& replace_filename(const path& replacement);
`

[9](#9)

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

*Effects*: Equivalent to:remove_filename();operator/=(replacement);

[10](#10)

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

*Returns*: *this[.](#10.sentence-1)

[11](#11)

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

[*Example [3](#example-3)*: path("/foo").replace_filename("bar"); // yields "/bar" on POSIX path("/").replace_filename("bar"); // yields "/bar" on POSIX â *end example*]

[ð](#lib:replace_extension,path)

`path& replace_extension(const path& replacement = path());
`

[12](#12)

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

*Effects*: 

- [(12.1)](#12.1)

Any existing extension() ([[fs.path.decompose]](fs.path.decompose "31.12.6.5.9 Decomposition")) is removed from the
 pathname in the generic format,
 then

- [(12.2)](#12.2)

If replacement is not empty and does not begin with a dot
 character, a dot character is appended to the pathname in the generic format, then

- [(12.3)](#12.3)

operator+=(replacement);[.](#12.sentence-1)

[13](#13)

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

*Returns*: *this[.](#13.sentence-1)

[ð](#lib:swap,path)

`void swap(path& rhs) noexcept;
`

[14](#14)

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

*Effects*: Swaps the contents (in all formats) of the two paths[.](#14.sentence-1)

[15](#15)

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

*Complexity*: Constant time[.](#15.sentence-1)
