[filesystems]

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

## 31.12 File systems [filesystems]

### [31.12.1](#fs.general) General [[fs.general]](fs.general)

[1](#fs.general-1)

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

Subclause [filesystems] describes operations on file systems and their components, such as paths,
regular files, and directories[.](#fs.general-1.sentence-1)

[2](#fs.general-2)

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

A [*file system*](#def:file_system "31.12.1 General [fs.general]") is
a collection of files and their attributes[.](#fs.general-2.sentence-1)

[3](#fs.general-3)

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

A [*file*](#def:file "31.12.1 General [fs.general]") is
an object within a file system that holds user or system data[.](#fs.general-3.sentence-1)

Files can be written to, or read from, or both[.](#fs.general-3.sentence-2)

A file
has certain attributes, including type[.](#fs.general-3.sentence-3)

File types include regular files
and directories[.](#fs.general-3.sentence-4)

Other types of files, such as symbolic links,
may be supported by the implementation[.](#fs.general-3.sentence-5)

[4](#fs.general-4)

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

A [*directory*](#def:directory "31.12.1 General [fs.general]") is
a file within a file system that acts as a container of directory entries
that contain information about
other files, possibly including other directory files[.](#fs.general-4.sentence-1)

The [*parent directory*](#def:parent_directory "31.12.1 General [fs.general]") of a directory is
the directory that both contains a
directory entry for the given directory and is represented by the dot-dot
filename ([[fs.path.generic]](#fs.path.generic "31.12.6.2 Generic pathname format")) in the given directory[.](#fs.general-4.sentence-2)

The [*parent directory*](#def:parent_directory "31.12.1 General [fs.general]") of other types of files is a directory containing a directory
entry for the file under discussion[.](#fs.general-4.sentence-3)

[5](#fs.general-5)

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

A [*link*](#def:link "31.12.1 General [fs.general]") is
an object that associates a filename with a file[.](#fs.general-5.sentence-1)

Several links can associate names with the same file[.](#fs.general-5.sentence-2)

A [*hard link*](#def:hard_link "31.12.1 General [fs.general]") is
a link to an existing file[.](#fs.general-5.sentence-3)

Some
file systems support multiple hard links to a file[.](#fs.general-5.sentence-4)

If the last hard link to a
file is removed, the file itself is removed[.](#fs.general-5.sentence-5)

[*Note [1](#fs.general-note-1)*:

A hard link can be thought of as a shared-ownership smart
pointer to a file[.](#fs.general-5.sentence-6)

â *end note*]

A [*symbolic link*](#def:symbolic_link "31.12.1 General [fs.general]") is
a type of file with the
property that when the file is encountered during pathname resolution ([[fs.class.path]](#fs.class.path "31.12.6 Class path")), a string
stored by the file is used to modify the pathname resolution[.](#fs.general-5.sentence-7)

[*Note [2](#fs.general-note-2)*:

Symbolic links are often called symlinks[.](#fs.general-5.sentence-8)

A symbolic link can be thought of as a raw pointer to a file[.](#fs.general-5.sentence-9)

If the file pointed to does not exist, the symbolic link is said to be a
âdanglingâ symbolic link[.](#fs.general-5.sentence-10)

â *end note*]

### [31.12.2](#fs.conformance) Conformance [[fs.conformance]](fs.conformance)

#### [31.12.2.1](#fs.conformance.general) General [[fs.conformance.general]](fs.conformance.general)

[1](#fs.conformance.general-1)

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

Conformance is specified in terms of behavior[.](#fs.conformance.general-1.sentence-1)

Ideal behavior is not always
implementable, so the conformance subclauses take that into account[.](#fs.conformance.general-1.sentence-2)

#### [31.12.2.2](#fs.conform.9945) POSIX conformance [[fs.conform.9945]](fs.conform.9945)

[1](#fs.conform.9945-1)

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

Some behavior is specified by reference to POSIX[.](#fs.conform.9945-1.sentence-1)

How such behavior is actually implemented is unspecified[.](#fs.conform.9945-1.sentence-2)

[*Note [1](#fs.conform.9945-note-1)*:

This constitutes an âas ifâ rule allowing implementations
to call native
operating system or other APIs[.](#fs.conform.9945-1.sentence-3)

â *end note*]

[2](#fs.conform.9945-2)

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

Implementations should provide such behavior as it is defined by
POSIX[.](#fs.conform.9945-2.sentence-1)

Implementations shall document any behavior that differs from the
behavior defined by POSIX[.](#fs.conform.9945-2.sentence-2)

Implementations that do not support exact POSIX
behavior should provide behavior as close to POSIX behavior as is reasonable given the
limitations of actual operating systems and file systems[.](#fs.conform.9945-2.sentence-3)

If an implementation cannot provide any
reasonable behavior, the implementation shall report an error as specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.conform.9945-2.sentence-4)

[*Note [2](#fs.conform.9945-note-2)*:

This allows users to rely on an exception being thrown or
an error code being set when an implementation cannot provide any reasonable
behavior[.](#fs.conform.9945-2.sentence-5)

â *end note*]

[3](#fs.conform.9945-3)

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

Implementations are not required to provide behavior that is not supported by
a particular file system[.](#fs.conform.9945-3.sentence-1)

[*Example [1](#fs.conform.9945-example-1)*:

The FAT file system used by some memory cards, camera memory, and
floppy disks does not support hard links, symlinks, and many other features of
more capable file systems, so implementations are not required to support those
features on the FAT file system
but instead are required to report an error as described above[.](#fs.conform.9945-3.sentence-2)

â *end example*]

#### [31.12.2.3](#fs.conform.os) Operating system dependent behavior conformance [[fs.conform.os]](fs.conform.os)

[1](#fs.conform.os-1)

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

Behavior that is specified as being[*operating system dependent*](#def:operating_system_dependent "31.12.2.3 Operating system dependent behavior conformance [fs.conform.os]") is dependent upon the behavior
and characteristics of an operating system[.](#fs.conform.os-1.sentence-1)

The operating system an
implementation is dependent upon isimplementation-defined[.](#fs.conform.os-1.sentence-2)

[2](#fs.conform.os-2)

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

It is permissible for an implementation to be dependent upon an operating
system emulator rather than the actual underlying operating system[.](#fs.conform.os-2.sentence-1)

#### [31.12.2.4](#fs.race.behavior) File system race behavior [[fs.race.behavior]](fs.race.behavior)

[1](#fs.race.behavior-1)

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

A [*file system race*](#def:file_system_race "31.12.2.4 File system race behavior [fs.race.behavior]") is
the condition that occurs
when multiple threads, processes, or computers interleave access and
modification of
the same object within a file system[.](#fs.race.behavior-1.sentence-1)

Behavior is undefined if calls to functions provided by subclause [filesystems] introduce a file system race[.](#fs.race.behavior-1.sentence-2)

[2](#fs.race.behavior-2)

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

If the possibility of a file system race would make it unreliable for a
program to test for a precondition before calling a function described herein,*Preconditions*: is not specified for the function[.](#fs.race.behavior-2.sentence-1)

[*Note [1](#fs.race.behavior-note-1)*:

As a design practice, preconditions are not specified when it
is unreasonable for a program to detect them prior to calling the function[.](#fs.race.behavior-2.sentence-2)

â *end note*]

### [31.12.3](#fs.req) Requirements [[fs.req]](fs.req)

[1](#fs.req-1)

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

Throughout subclause [filesystems], char, wchar_t, char8_t,char16_t, and char32_t are collectively called[*encoded character types*](#def:encoded_character_type "31.12.3 Requirements [fs.req]")[.](#fs.req-1.sentence-1)

[2](#fs.req-2)

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

Functions with template parameters named EcharT shall not participate in overload resolution
unless EcharT is one of the encoded character types[.](#fs.req-2.sentence-1)

[3](#fs.req-3)

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

Template parameters named InputIterator shall meet the[*Cpp17InputIterator*](input.iterators#:Cpp17InputIterator "24.3.5.3 Input iterators [input.iterators]") requirements ([[input.iterators]](input.iterators "24.3.5.3 Input iterators")) and shall
have a value type that is one of the encoded character types[.](#fs.req-3.sentence-1)

[4](#fs.req-4)

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

[*Note [1](#fs.req-note-1)*:

Use of an encoded character type implies an associated
character set and encoding[.](#fs.req-4.sentence-1)

Since signed char and unsigned char have no
implied character set and encoding,
they are not included as permitted types[.](#fs.req-4.sentence-2)

â *end note*]

[5](#fs.req-5)

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

Template parameters named Allocator shall meet
the [*Cpp17Allocator*](allocator.requirements.general#:Cpp17Allocator "16.4.4.6.1 General [allocator.requirements.general]") requirements ([[allocator.requirements.general]](allocator.requirements.general "16.4.4.6.1 General"))[.](#fs.req-5.sentence-1)

### [31.12.4](#fs.filesystem.syn) Header <filesystem> synopsis [[fs.filesystem.syn]](fs.filesystem.syn)

[ð](#header:%3cfilesystem%3e)

#include <compare> // see [[compare.syn]](compare.syn "17.12.1 Header <compare> synopsis")namespace std::filesystem {// [[fs.class.path]](#fs.class.path "31.12.6 Class path"), pathsclass path; // [[fs.path.nonmember]](#fs.path.nonmember "31.12.6.8 Non-member functions"), path non-member functionsvoid swap(path& lhs, path& rhs) noexcept;
 size_t hash_value(const path& p) noexcept; // [[fs.class.filesystem.error]](#fs.class.filesystem.error "31.12.7 Class filesystem_­error"), filesystem errorsclass filesystem_error; // [[fs.class.directory.entry]](#fs.class.directory.entry "31.12.10 Class directory_­entry"), directory entriesclass directory_entry; // [[fs.class.directory.iterator]](#fs.class.directory.iterator "31.12.11 Class directory_­iterator"), directory iteratorsclass directory_iterator; // [[fs.dir.itr.nonmembers]](#fs.dir.itr.nonmembers "31.12.11.3 Non-member functions"), range access for directory iterators directory_iterator begin(directory_iterator iter) noexcept;
 directory_iterator end(directory_iterator) noexcept; // [[fs.class.rec.dir.itr]](#fs.class.rec.dir.itr "31.12.12 Class recursive_­directory_­iterator"), recursive directory iteratorsclass recursive_directory_iterator; // [[fs.rec.dir.itr.nonmembers]](#fs.rec.dir.itr.nonmembers "31.12.12.3 Non-member functions"), range access for recursive directory iterators recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept;
 recursive_directory_iterator end(recursive_directory_iterator) noexcept; // [[fs.class.file.status]](#fs.class.file.status "31.12.9 Class file_­status"), file statusclass file_status; struct space_info { uintmax_t capacity;
 uintmax_t free;
 uintmax_t available; friend bool operator==(const space_info&, const space_info&) = default; }; // [[fs.enum]](#fs.enum "31.12.8 Enumerations"), enumerationsenum class file_type; enum class perms; enum class perm_options; enum class copy_options; enum class directory_options; using file_time_type = chrono::time_point<chrono::file_clock>; // [[fs.op.funcs]](#fs.op.funcs "31.12.13 Filesystem operation functions"), filesystem operations path absolute(const path& p);
 path absolute(const path& p, error_code& ec);

 path canonical(const path& p);
 path canonical(const path& p, error_code& ec); void copy(const path& from, const path& to); void copy(const path& from, const path& to, error_code& ec); void copy(const path& from, const path& to, copy_options options); void copy(const path& from, const path& to, copy_options options,
 error_code& ec); bool copy_file(const path& from, const path& to); bool copy_file(const path& from, const path& to, error_code& ec); bool copy_file(const path& from, const path& to, copy_options option); bool copy_file(const path& from, const path& to, copy_options option,
 error_code& ec); void copy_symlink(const path& existing_symlink, const path& new_symlink); void copy_symlink(const path& existing_symlink, const path& new_symlink,
 error_code& ec) noexcept; bool create_directories(const path& p); bool create_directories(const path& p, error_code& ec); bool create_directory(const path& p); bool create_directory(const path& p, error_code& ec) noexcept; bool create_directory(const path& p, const path& attributes); bool create_directory(const path& p, const path& attributes,
 error_code& ec) noexcept; void create_directory_symlink(const path& to, const path& new_symlink); void create_directory_symlink(const path& to, const path& new_symlink,
 error_code& ec) noexcept; void create_hard_link(const path& to, const path& new_hard_link); void create_hard_link(const path& to, const path& new_hard_link,
 error_code& ec) noexcept; void create_symlink(const path& to, const path& new_symlink); void create_symlink(const path& to, const path& new_symlink,
 error_code& ec) noexcept;

 path current_path();
 path current_path(error_code& ec); void current_path(const path& p); void current_path(const path& p, error_code& ec) noexcept; bool equivalent(const path& p1, const path& p2); bool equivalent(const path& p1, const path& p2, error_code& ec) noexcept; bool exists(file_status s) noexcept; bool exists(const path& p); bool exists(const path& p, error_code& ec) noexcept;

 uintmax_t file_size(const path& p);
 uintmax_t file_size(const path& p, error_code& ec) noexcept;

 uintmax_t hard_link_count(const path& p);
 uintmax_t hard_link_count(const path& p, error_code& ec) noexcept; bool is_block_file(file_status s) noexcept; bool is_block_file(const path& p); bool is_block_file(const path& p, error_code& ec) noexcept; bool is_character_file(file_status s) noexcept; bool is_character_file(const path& p); bool is_character_file(const path& p, error_code& ec) noexcept; bool is_directory(file_status s) noexcept; bool is_directory(const path& p); bool is_directory(const path& p, error_code& ec) noexcept; bool is_empty(const path& p); bool is_empty(const path& p, error_code& ec); bool is_fifo(file_status s) noexcept; bool is_fifo(const path& p); bool is_fifo(const path& p, error_code& ec) noexcept; bool is_other(file_status s) noexcept; bool is_other(const path& p); bool is_other(const path& p, error_code& ec) noexcept; bool is_regular_file(file_status s) noexcept; bool is_regular_file(const path& p); bool is_regular_file(const path& p, error_code& ec) noexcept; bool is_socket(file_status s) noexcept; bool is_socket(const path& p); bool is_socket(const path& p, error_code& ec) noexcept; bool is_symlink(file_status s) noexcept; bool is_symlink(const path& p); bool is_symlink(const path& p, error_code& ec) noexcept;

 file_time_type last_write_time(const path& p);
 file_time_type last_write_time(const path& p, error_code& ec) noexcept; void last_write_time(const path& p, file_time_type new_time); void last_write_time(const path& p, file_time_type new_time,
 error_code& ec) noexcept; void permissions(const path& p, perms prms, perm_options opts=perm_options::replace); void permissions(const path& p, perms prms, error_code& ec) noexcept; void permissions(const path& p, perms prms, perm_options opts, error_code& ec);

 path proximate(const path& p, error_code& ec);
 path proximate(const path& p, const path& base = current_path());
 path proximate(const path& p, const path& base, error_code& ec);

 path read_symlink(const path& p);
 path read_symlink(const path& p, error_code& ec);

 path relative(const path& p, error_code& ec);
 path relative(const path& p, const path& base = current_path());
 path relative(const path& p, const path& base, error_code& ec); bool remove(const path& p); bool remove(const path& p, error_code& ec) noexcept;

 uintmax_t remove_all(const path& p);
 uintmax_t remove_all(const path& p, error_code& ec); void rename(const path& from, const path& to); void rename(const path& from, const path& to, error_code& ec) noexcept; void resize_file(const path& p, uintmax_t size); void resize_file(const path& p, uintmax_t size, error_code& ec) noexcept;

 space_info space(const path& p);
 space_info space(const path& p, error_code& ec) noexcept;

 file_status status(const path& p);
 file_status status(const path& p, error_code& ec) noexcept; bool status_known(file_status s) noexcept;

 file_status symlink_status(const path& p);
 file_status symlink_status(const path& p, error_code& ec) noexcept;

 path temp_directory_path();
 path temp_directory_path(error_code& ec);

 path weakly_canonical(const path& p);
 path weakly_canonical(const path& p, error_code& ec);}namespace std {// [[fs.path.fmtr]](#fs.path.fmtr "31.12.6.9 Formatting support"), formatting supporttemplate<class charT> struct formatter<filesystem::path, charT>; // [[fs.path.hash]](#fs.path.hash "31.12.6.10 Hash support"), hash supporttemplate<class T> struct hash; template<> struct hash<filesystem::path>;}namespace std::ranges {template<>inline constexpr bool enable_borrowed_range<filesystem::directory_iterator> = true; template<>inline constexpr bool enable_borrowed_range<filesystem::recursive_directory_iterator> = true; template<>inline constexpr bool enable_view<filesystem::directory_iterator> = true; template<>inline constexpr bool enable_view<filesystem::recursive_directory_iterator> = true;}

[1](#fs.filesystem.syn-1)

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

Implementations should ensure that the resolution and range offile_time_type reflect the operating system dependent resolution and range
of file time values[.](#fs.filesystem.syn-1.sentence-1)

### [31.12.5](#fs.err.report) Error reporting [[fs.err.report]](fs.err.report)

[1](#fs.err.report-1)

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

Filesystem library functions often provide two overloads, one that
throws an exception to report file system errors, and another that sets an error_code[.](#fs.err.report-1.sentence-1)

[*Note [1](#fs.err.report-note-1)*:

This supports two common use cases:

- [(1.1)](#fs.err.report-1.1)

  Uses where file system errors are truly exceptional
and indicate a serious failure[.](#fs.err.report-1.1.sentence-1)
  Throwing an exception is an appropriate response[.](#fs.err.report-1.1.sentence-2)

- [(1.2)](#fs.err.report-1.2)

  Uses where file system errors are routine
and do not necessarily represent failure[.](#fs.err.report-1.2.sentence-1)
  Returning an error code is the most appropriate response[.](#fs.err.report-1.2.sentence-2)
  This allows application specific error handling, including simply ignoring the error[.](#fs.err.report-1.2.sentence-3)

â *end note*]

[2](#fs.err.report-2)

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

Functions not having an argument of type error_code& handle errors as follows, unless otherwise specified:

- [(2.1)](#fs.err.report-2.1)

  When a call by the
 implementation to an operating system or other underlying API results in an
 error that prevents the function from meeting its specifications, an exception
 of typefilesystem_error shall be thrown[.](#fs.err.report-2.1.sentence-1)
  For functions with a single path
 argument, that argument shall be passed to thefilesystem_error constructor with a single path argument[.](#fs.err.report-2.1.sentence-2)
  For
 functions with two path arguments, the first of these arguments shall be
 passed to thefilesystem_error constructor as the path1 argument,
 and the second shall be passed as the path2 argument[.](#fs.err.report-2.1.sentence-3)
  The filesystem_error constructor's error_code argument
 is set as appropriate for the specific operating system dependent error[.](#fs.err.report-2.1.sentence-4)

- [(2.2)](#fs.err.report-2.2)

  Failure to allocate storage is reported by throwing an exception
as described in [[res.on.exception.handling]](res.on.exception.handling "16.4.6.14 Restrictions on exception handling")[.](#fs.err.report-2.2.sentence-1)

- [(2.3)](#fs.err.report-2.3)

  Destructors throw nothing[.](#fs.err.report-2.3.sentence-1)

[3](#fs.err.report-3)

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

Functions having an argument of type error_code& handle errors as follows, unless otherwise specified:

- [(3.1)](#fs.err.report-3.1)

If a call by the
 implementation to an operating system or other underlying API results in an
 error that prevents the function from meeting its specifications, the error_code& argument is set as
 appropriate for the specific operating system dependent error[.](#fs.err.report-3.sentence-1)
  Otherwise, clear() is called on the error_code& argument[.](#fs.err.report-3.1.sentence-2)

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

#### [31.12.6.1](#fs.class.path.general) General [[fs.class.path.general]](fs.class.path.general)

[1](#fs.class.path.general-1)

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

An object of class path represents a path
and contains a pathname[.](#fs.class.path.general-1.sentence-1)

Such an object is concerned only with the lexical and syntactic aspects
of a path[.](#fs.class.path.general-1.sentence-2)

The path does not necessarily exist in external storage, and the
pathname is not necessarily valid for the current operating
system or for a particular file system[.](#fs.class.path.general-1.sentence-3)

[2](#fs.class.path.general-2)

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

[*Note [1](#fs.class.path.general-note-1)*:

Class path is used to support the differences
between the string types used by different operating systems
to represent pathnames,
and to perform conversions between encodings when necessary[.](#fs.class.path.general-2.sentence-1)

â *end note*]

[3](#fs.class.path.general-3)

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

A [*path*](#def:path "31.12.6.1 General [fs.class.path.general]") is
a sequence of elements that identify
the location of a file within a filesystem[.](#fs.class.path.general-3.sentence-1)

The elements are the[*root-name*](#nt:root-name "31.12.6.2 Generic pathname format [fs.path.generic]")opt,[*root-directory*](#nt:root-directory "31.12.6.2 Generic pathname format [fs.path.generic]")opt,
and an optional sequence of [*filename*](#nt:filename "31.12.6.2 Generic pathname format [fs.path.generic]")*s* ([[fs.path.generic]](#fs.path.generic "31.12.6.2 Generic pathname format"))[.](#fs.class.path.general-3.sentence-2)

The maximum number of elements in the sequence is
operating system dependent ([[fs.conform.os]](#fs.conform.os "31.12.2.3 Operating system dependent behavior conformance"))[.](#fs.class.path.general-3.sentence-3)

[4](#fs.class.path.general-4)

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

An [*absolute path*](#def:path,absolute "31.12.6.1 General [fs.class.path.general]") is a path that unambiguously
identifies the location of a file without reference to an additional starting
location[.](#fs.class.path.general-4.sentence-1)

The elements of a path that determine if it is absolute are
operating system dependent[.](#fs.class.path.general-4.sentence-2)

A [*relative path*](#def:path,relative "31.12.6.1 General [fs.class.path.general]") is
a path that is not absolute, and as such, only unambiguously
identifies the location of a file when resolved relative to
an implied starting location[.](#fs.class.path.general-4.sentence-3)

The elements of a path that determine if it is
relative are operating system dependent[.](#fs.class.path.general-4.sentence-4)

[*Note [2](#fs.class.path.general-note-2)*:

Pathnames â.â and â..â are relative paths[.](#fs.class.path.general-4.sentence-5)

â *end note*]

[5](#fs.class.path.general-5)

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

A [*pathname*](#def:pathname "31.12.6.1 General [fs.class.path.general]") is
a character string that represents the name of a path[.](#fs.class.path.general-5.sentence-1)

Pathnames are
formatted according to the generic pathname format grammar ([[fs.path.generic]](#fs.path.generic "31.12.6.2 Generic pathname format"))
or according to an
operating system dependent[*native pathname format*](#def:native_pathname_format "31.12.6.1 General [fs.class.path.general]") accepted by the host operating system[.](#fs.class.path.general-5.sentence-2)

[6](#fs.class.path.general-6)

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

[*Pathname resolution*](#def:pathname_resolution "31.12.6.1 General [fs.class.path.general]") is the operating system dependent mechanism for resolving
a pathname to a particular file in a file hierarchy[.](#fs.class.path.general-6.sentence-1)

There may be multiple
pathnames that resolve to the same file[.](#fs.class.path.general-6.sentence-2)

[*Example [1](#fs.class.path.general-example-1)*:

For POSIX-based operating systems,
this mechanism is specified in POSIX, section 4.12, Pathname resolution[.](#fs.class.path.general-6.sentence-3)

â *end example*]

namespace std::filesystem {class path {public:using value_type = *see below*; using string_type = basic_string<value_type>; static constexpr value_type preferred_separator = *see below*; // [[fs.enum.path.format]](#fs.enum.path.format "31.12.8.1 Enum path​::​format"), enumeration formatenum format; // [[fs.path.construct]](#fs.path.construct "31.12.6.5.1 Constructors"), constructors and destructor path() noexcept;
 path(const path& p);
 path(path&& p) noexcept;
 path(string_type&& source, format fmt = auto_format); template<class Source> path(const Source& source, format fmt = auto_format); template<class InputIterator> path(InputIterator first, InputIterator last, format fmt = auto_format); template<class Source> path(const Source& source, const locale& loc, format fmt = auto_format); template<class InputIterator> path(InputIterator first, InputIterator last, const locale& loc, format fmt = auto_format); ~path(); // [[fs.path.assign]](#fs.path.assign "31.12.6.5.2 Assignments"), assignments path& operator=(const path& p);
 path& operator=(path&& p) noexcept;
 path& operator=(string_type&& source);
 path& assign(string_type&& source); template<class Source> path& operator=(const Source& source); template<class Source> path& assign(const Source& source); template<class InputIterator> path& assign(InputIterator first, InputIterator last); // [[fs.path.append]](#fs.path.append "31.12.6.5.3 Appends"), appends path& operator/=(const path& p); template<class Source> path& operator/=(const Source& source); template<class Source> path& append(const Source& source); template<class InputIterator> path& append(InputIterator first, InputIterator last); // [[fs.path.concat]](#fs.path.concat "31.12.6.5.4 Concatenation"), concatenation path& operator+=(const path& x);
 path& operator+=(const string_type& x);
 path& operator+=(basic_string_view<value_type> x);
 path& operator+=(const value_type* x);
 path& operator+=(value_type x); template<class Source> path& operator+=(const Source& x); template<class EcharT> path& operator+=(EcharT x); template<class Source> path& concat(const Source& x); template<class InputIterator> path& concat(InputIterator first, InputIterator last); // [[fs.path.modifiers]](#fs.path.modifiers "31.12.6.5.5 Modifiers"), modifiersvoid clear() noexcept;
 path& make_preferred();
 path& remove_filename();
 path& replace_filename(const path& replacement);
 path& replace_extension(const path& replacement = path()); void swap(path& rhs) noexcept; // [[fs.path.nonmember]](#fs.path.nonmember "31.12.6.8 Non-member functions"), non-member operatorsfriend bool operator==(const path& lhs, const path& rhs) noexcept; friend strong_ordering operator<=>(const path& lhs, const path& rhs) noexcept; friend path operator/(const path& lhs, const path& rhs); // [[fs.path.native.obs]](#fs.path.native.obs "31.12.6.5.6 Native format observers"), native format observersconst string_type& native() const noexcept; const value_type* c_str() const noexcept; operator string_type() const; template<class EcharT, class traits = char_traits<EcharT>, class Allocator = allocator<EcharT>> basic_string<EcharT, traits, Allocator> string(const Allocator& a = Allocator()) const;
 std::string display_string() const;
 std::string system_encoded_string() const;
 std::wstring wstring() const;
 std::u8string u8string() const;
 std::u16string u16string() const;
 std::u32string u32string() const; // [[fs.path.generic.obs]](#fs.path.generic.obs "31.12.6.5.7 Generic format observers"), generic format observerstemplate<class EcharT, class traits = char_traits<EcharT>, class Allocator = allocator<EcharT>> basic_string<EcharT, traits, Allocator> generic_string(const Allocator& a = Allocator()) const;
 std::string generic_display_string() const;
 std::string generic_system_encoded_string() const;
 std::wstring generic_wstring() const;
 std::u8string generic_u8string() const;
 std::u16string generic_u16string() const;
 std::u32string generic_u32string() const; // [[fs.path.compare]](#fs.path.compare "31.12.6.5.8 Compare"), compareint compare(const path& p) const noexcept; int compare(const string_type& s) const; int compare(basic_string_view<value_type> s) const; int compare(const value_type* s) const; // [[fs.path.decompose]](#fs.path.decompose "31.12.6.5.9 Decomposition"), decomposition path root_name() const;
 path root_directory() const;
 path root_path() const;
 path relative_path() const;
 path parent_path() const;
 path filename() const;
 path stem() const;
 path extension() const; // [[fs.path.query]](#fs.path.query "31.12.6.5.10 Query"), querybool empty() const noexcept; bool has_root_name() const; bool has_root_directory() const; bool has_root_path() const; bool has_relative_path() const; bool has_parent_path() const; bool has_filename() const; bool has_stem() const; bool has_extension() const; bool is_absolute() const; bool is_relative() const; // [[fs.path.gen]](#fs.path.gen "31.12.6.5.11 Generation"), generation path lexically_normal() const;
 path lexically_relative(const path& base) const;
 path lexically_proximate(const path& base) const; // [[fs.path.itr]](#fs.path.itr "31.12.6.6 Iterators"), iteratorsclass iterator; using const_iterator = iterator;

 iterator begin() const;
 iterator end() const; // [[fs.path.io]](#fs.path.io "31.12.6.7 Inserter and extractor"), path inserter and extractortemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const path& p); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, path& p); };}

[7](#fs.class.path.general-7)

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

value_type is a typedef for the
operating system dependent encoded character type used to represent pathnames[.](#fs.class.path.general-7.sentence-1)

[8](#fs.class.path.general-8)

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

The value of the preferred_separator member
is the operating system dependent [*preferred-separator*](#nt:preferred-separator "31.12.6.2 Generic pathname format [fs.path.generic]") character ([[fs.path.generic]](#fs.path.generic "31.12.6.2 Generic pathname format"))[.](#fs.class.path.general-8.sentence-1)

[9](#fs.class.path.general-9)

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

[*Example [2](#fs.class.path.general-example-2)*:

For POSIX-based operating systems,value_type is char andpreferred_separator is the slash character ('/')[.](#fs.class.path.general-9.sentence-1)

For Windows-based operating systems,value_type is wchar_t andpreferred_separator is the backslash character (L'\\')[.](#fs.class.path.general-9.sentence-2)

â *end example*]

#### [31.12.6.2](#fs.path.generic) Generic pathname format [[fs.path.generic]](fs.path.generic)

[pathname:](#nt:pathname "31.12.6.2 Generic pathname format [fs.path.generic]")  
[*root-name*](#nt:root-name "31.12.6.2 Generic pathname format [fs.path.generic]")opt [*root-directory*](#nt:root-directory "31.12.6.2 Generic pathname format [fs.path.generic]")opt [*relative-path*](#nt:relative-path "31.12.6.2 Generic pathname format [fs.path.generic]")

[root-name:](#nt:root-name "31.12.6.2 Generic pathname format [fs.path.generic]")  
operating system dependent sequences of characters  
implementation-defined sequences of characters

[root-directory:](#nt:root-directory "31.12.6.2 Generic pathname format [fs.path.generic]")  
[*directory-separator*](#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]")

[relative-path:](#nt:relative-path "31.12.6.2 Generic pathname format [fs.path.generic]")  
[*filename*](#nt:filename "31.12.6.2 Generic pathname format [fs.path.generic]")  
[*filename*](#nt:filename "31.12.6.2 Generic pathname format [fs.path.generic]") [*directory-separator*](#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]") [*relative-path*](#nt:relative-path "31.12.6.2 Generic pathname format [fs.path.generic]")  
an empty path

[filename:](#nt:filename "31.12.6.2 Generic pathname format [fs.path.generic]")  
non-empty sequence of characters other than [*directory-separator*](#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]") characters

[directory-separator:](#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]")  
[*preferred-separator*](#nt:preferred-separator "31.12.6.2 Generic pathname format [fs.path.generic]") [*directory-separator*](#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]")opt  
[*fallback-separator*](#nt:fallback-separator "31.12.6.2 Generic pathname format [fs.path.generic]") [*directory-separator*](#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]")opt

[preferred-separator:](#nt:preferred-separator "31.12.6.2 Generic pathname format [fs.path.generic]")  
operating system dependent directory separator character

[fallback-separator:](#nt:fallback-separator "31.12.6.2 Generic pathname format [fs.path.generic]")  
/, if [*preferred-separator*](#nt:preferred-separator "31.12.6.2 Generic pathname format [fs.path.generic]") is not /

[1](#fs.path.generic-1)

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

A [*filename*](#def:filename "31.12.6.2 Generic pathname format [fs.path.generic]") is
the name of a file[.](#fs.path.generic-1.sentence-1)

The [*dot*](#def:dot,filename "31.12.6.2 Generic pathname format [fs.path.generic]") and [*dot-dot*](#def:dot-dot,filename "31.12.6.2 Generic pathname format [fs.path.generic]") filenames,
consisting solely of one and two period characters respectively,
have special meaning[.](#fs.path.generic-1.sentence-2)

The following characteristics of filenames are operating system dependent:

- [(1.1)](#fs.path.generic-1.1)

  The permitted characters[.](#fs.path.generic-1.1.sentence-1)
  [*Example [1](#fs.path.generic-example-1)*:
  Some operating systems prohibit
 the ASCII control characters (0x00 â 0x1F) in filenames[.](#fs.path.generic-1.1.sentence-2)
 â *end example*]
  [*Note [1](#fs.path.generic-note-1)*:
  Wider portability can be achieved by limiting [*filename*](#nt:filename "31.12.6.2 Generic pathname format [fs.path.generic]") characters to the POSIX Portable Filename Character Set:   
  A B C D E F G H I J K L M N O P Q R S T U V W X Y Z   
  a b c d e f g h i j k l m n o p q r s t u v w x y z   
  0 1 2 3 4 5 6 7 8 9 . _ -
 â *end note*]

- [(1.2)](#fs.path.generic-1.2)

  The maximum permitted length[.](#fs.path.generic-1.2.sentence-1)

- [(1.3)](#fs.path.generic-1.3)

  Filenames that are not permitted[.](#fs.path.generic-1.3.sentence-1)

- [(1.4)](#fs.path.generic-1.4)

  Filenames that have special meaning[.](#fs.path.generic-1.4.sentence-1)

- [(1.5)](#fs.path.generic-1.5)

  Case awareness and sensitivity during path resolution[.](#fs.path.generic-1.5.sentence-1)

- [(1.6)](#fs.path.generic-1.6)

  Special rules that may apply to file types other than regular
 files, such as directories[.](#fs.path.generic-1.6.sentence-1)

[2](#fs.path.generic-2)

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

Except in a [*root-name*](#nt:root-name "31.12.6.2 Generic pathname format [fs.path.generic]"),
multiple successive [*directory-separator*](#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]") characters are considered to
be the same as one [*directory-separator*](#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]") character[.](#fs.path.generic-2.sentence-1)

[3](#fs.path.generic-3)

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

The dot filename is treated as a reference to the current directory[.](#fs.path.generic-3.sentence-1)

The dot-dot filename is treated as a reference to the parent directory[.](#fs.path.generic-3.sentence-2)

What the dot-dot filename refers to
relative to [*root-directory*](#nt:root-directory "31.12.6.2 Generic pathname format [fs.path.generic]") is implementation-defined[.](#fs.path.generic-3.sentence-3)

Specific filenames may have special meanings for a particular operating system[.](#fs.path.generic-3.sentence-4)

[4](#fs.path.generic-4)

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

A [*root-name*](#nt:root-name "31.12.6.2 Generic pathname format [fs.path.generic]") identifies the
starting location for pathname resolution ([[fs.class.path]](#fs.class.path "31.12.6 Class path"))[.](#fs.path.generic-4.sentence-1)

If there are no operating system dependent [*root-name*](#nt:root-name "31.12.6.2 Generic pathname format [fs.path.generic]")*s*,
at least one implementation-defined [*root-name*](#nt:root-name "31.12.6.2 Generic pathname format [fs.path.generic]") is required[.](#fs.path.generic-4.sentence-2)

[*Note [2](#fs.path.generic-note-2)*:

Many operating systems define a name
beginning with two [*directory-separator*](#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]") characters
as a [*root-name*](#nt:root-name "31.12.6.2 Generic pathname format [fs.path.generic]") that identifies
network or other resource locations[.](#fs.path.generic-4.sentence-3)

Some operating systems
define a single letter followed by a colon
as a drive specifier â a [*root-name*](#nt:root-name "31.12.6.2 Generic pathname format [fs.path.generic]") identifying a specific device such as a disk drive[.](#fs.path.generic-4.sentence-4)

â *end note*]

[5](#fs.path.generic-5)

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

If a [*root-name*](#nt:root-name "31.12.6.2 Generic pathname format [fs.path.generic]") is otherwise ambiguous,
the possibility with the longest sequence of characters is chosen[.](#fs.path.generic-5.sentence-1)

[*Note [3](#fs.path.generic-note-3)*:

On a POSIX-like operating system, it is impossible to have a[*root-name*](#nt:root-name "31.12.6.2 Generic pathname format [fs.path.generic]") and a [*relative-path*](#nt:relative-path "31.12.6.2 Generic pathname format [fs.path.generic]") without an intervening [*root-directory*](#nt:root-directory "31.12.6.2 Generic pathname format [fs.path.generic]") element[.](#fs.path.generic-5.sentence-2)

â *end note*]

[6](#fs.path.generic-6)

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

[*Normalization*](#def:normalization,path "31.12.6.2 Generic pathname format [fs.path.generic]") of a generic format pathname means:

| [1.](#fs.path.generic-6.1) | If the path is empty, stop[.](#fs.path.generic-6.1.sentence-1) |
| --- | --- |
| [2.](#fs.path.generic-6.2) | Replace each slash character in the [*root-name*](#nt:root-name "31.12.6.2 Generic pathname format [fs.path.generic]") with a [*preferred-separator*](#nt:preferred-separator "31.12.6.2 Generic pathname format [fs.path.generic]")[.](#fs.path.generic-6.2.sentence-1) |
| [3.](#fs.path.generic-6.3) | Replace each [*directory-separator*](#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]") with a [*preferred-separator*](#nt:preferred-separator "31.12.6.2 Generic pathname format [fs.path.generic]")[.](#fs.path.generic-6.3.sentence-1)<br>[*Note [4](#fs.path.generic-note-4)*:<br>The generic pathname grammar defines [*directory-separator*](#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]") as one or more slashes and [*preferred-separator*](#nt:preferred-separator "31.12.6.2 Generic pathname format [fs.path.generic]")*s*[.](#fs.path.generic-6.3.sentence-2) â *end note*] |
| [4.](#fs.path.generic-6.4) | Remove each dot filename and any immediately following [*directory-separator*](#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]")[.](#fs.path.generic-6.4.sentence-1) |
| [5.](#fs.path.generic-6.5) | As long as any appear, remove a non-dot-dot filename immediately followed by a [*directory-separator*](#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]") and a dot-dot filename, along with any immediately following [*directory-separator*](#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]")[.](#fs.path.generic-6.5.sentence-1) |
| [6.](#fs.path.generic-6.6) | If there is a [*root-directory*](#nt:root-directory "31.12.6.2 Generic pathname format [fs.path.generic]"), remove all dot-dot filenames and any [*directory-separator*](#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]")*s* immediately following them[.](#fs.path.generic-6.6.sentence-1)<br>[*Note [5](#fs.path.generic-note-5)*:<br>These dot-dot filenames attempt to refer to nonexistent parent directories[.](#fs.path.generic-6.6.sentence-2) â *end note*] |
| [7.](#fs.path.generic-6.7) | If the last filename is dot-dot, remove any trailing [*directory-separator*](#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]")[.](#fs.path.generic-6.7.sentence-1) |
| [8.](#fs.path.generic-6.8) | If the path is empty, add a dot[.](#fs.path.generic-6.8.sentence-1) |

The result of normalization is a path in [*normal form*](#def:normal_form,path "31.12.6.2 Generic pathname format [fs.path.generic]"),
which is said to be [*normalized*](#def:normalized)[.](#fs.path.generic-6.sentence-2)

#### [31.12.6.3](#fs.path.cvt) Conversions [[fs.path.cvt]](fs.path.cvt)

#### [31.12.6.3.1](#fs.path.fmt.cvt) Argument format conversions [[fs.path.fmt.cvt]](fs.path.fmt.cvt)

[1](#fs.path.fmt.cvt-1)

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

[*Note [1](#fs.path.fmt.cvt-note-1)*:

The format conversions described in this subclause
are not applied on POSIX-based operating systems
because on these systems:

- [(1.1)](#fs.path.fmt.cvt-1.1)

  The generic format is acceptable as a native path[.](#fs.path.fmt.cvt-1.1.sentence-1)

- [(1.2)](#fs.path.fmt.cvt-1.2)

  There is no need to distinguish between native format and generic format in function arguments[.](#fs.path.fmt.cvt-1.2.sentence-1)

- [(1.3)](#fs.path.fmt.cvt-1.3)

  Paths for regular files and paths for directories share the same syntax[.](#fs.path.fmt.cvt-1.3.sentence-1)

â *end note*]

[2](#fs.path.fmt.cvt-2)

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

Several functions are defined to accept [*detected-format*](#def:detected-format) arguments,
which are character sequences[.](#fs.path.fmt.cvt-2.sentence-1)

A detected-format argument represents a path
using either a pathname in the generic format ([[fs.path.generic]](#fs.path.generic "31.12.6.2 Generic pathname format"))
or a pathname in the native format ([[fs.class.path]](#fs.class.path "31.12.6 Class path"))[.](#fs.path.fmt.cvt-2.sentence-2)

Such an argument is taken to be in the generic format if and only if
it matches the generic format and is not acceptable to the operating system
as a native path[.](#fs.path.fmt.cvt-2.sentence-3)

[3](#fs.path.fmt.cvt-3)

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

[*Note [2](#fs.path.fmt.cvt-note-2)*:

Some operating systems have no unambiguous way to distinguish between native format and generic format arguments[.](#fs.path.fmt.cvt-3.sentence-1)

This is by design as it simplifies use for operating systems that do not require
disambiguation[.](#fs.path.fmt.cvt-3.sentence-2)

It is possible that an implementation for an operating system
where disambiguation is needed distinguishes between the formats[.](#fs.path.fmt.cvt-3.sentence-3)

â *end note*]

[4](#fs.path.fmt.cvt-4)

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

Pathnames are converted as needed between the generic and native formats
in an operating-system-dependent manner[.](#fs.path.fmt.cvt-4.sentence-1)

Let *G(n)* and *N(g)* in a mathematical sense
be the implementation's functions that convert native-to-generic
and generic-to-native formats respectively[.](#fs.path.fmt.cvt-4.sentence-2)

If *g=G(n)* for some *n*, then *G(N(g))=g*;
if *n=N(g)* for some *g*, then *N(G(n))=n*[.](#fs.path.fmt.cvt-4.sentence-3)

[*Note [3](#fs.path.fmt.cvt-note-3)*:

Neither *G* nor *N* need be invertible[.](#fs.path.fmt.cvt-4.sentence-4)

â *end note*]

[5](#fs.path.fmt.cvt-5)

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

If the native format requires paths for regular files to be formatted
differently from paths for directories, the path shall be treated as a directory
path if its last element is a [*directory-separator*](#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]"),
otherwise it shall be treated as a path to a regular file[.](#fs.path.fmt.cvt-5.sentence-1)

[6](#fs.path.fmt.cvt-6)

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

[*Note [4](#fs.path.fmt.cvt-note-4)*:

A path stores a native format pathname ([[fs.path.native.obs]](#fs.path.native.obs "31.12.6.5.6 Native format observers"))
and acts as if it also stores a generic format pathname,
related as given below[.](#fs.path.fmt.cvt-6.sentence-1)

The implementation can generate the generic format pathname
based on the native format pathname (and possibly other information)
when requested[.](#fs.path.fmt.cvt-6.sentence-2)

â *end note*]

[7](#fs.path.fmt.cvt-7)

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

When a path is constructed from or is assigned a single representation
separate from any path, the other representation is selected
by the appropriate conversion function (*G* or *N*)[.](#fs.path.fmt.cvt-7.sentence-1)

[8](#fs.path.fmt.cvt-8)

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

When the (new) value *p* of one representation of a path
is derived from the representation of that or another path,
a value *q* is chosen for the other representation[.](#fs.path.fmt.cvt-8.sentence-1)

The value *q* converts to *p* (by *G* or *N* as appropriate)
if any such value does so;*q* is otherwise unspecified[.](#fs.path.fmt.cvt-8.sentence-2)

[*Note [5](#fs.path.fmt.cvt-note-5)*:

If *q* is the result of converting any path at all,
it is the result of converting *p*[.](#fs.path.fmt.cvt-8.sentence-3)

â *end note*]

#### [31.12.6.3.2](#fs.path.type.cvt) Type and encoding conversions [[fs.path.type.cvt]](fs.path.type.cvt)

[1](#fs.path.type.cvt-1)

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

The [*native encoding*](#def:native_encoding "31.12.6.3.2 Type and encoding conversions [fs.path.type.cvt]") of an ordinary character string is
the operating system dependent current encoding
for pathnames ([[fs.class.path]](#fs.class.path "31.12.6 Class path"))[.](#fs.path.type.cvt-1.sentence-1)

The [*native encoding*](#def:native_encoding "31.12.6.3.2 Type and encoding conversions [fs.path.type.cvt]") for wide character strings is
the implementation-defined execution
wide-character set encoding ([[character.seq]](character.seq "16.3.3.3.4 Character sequences"))[.](#fs.path.type.cvt-1.sentence-2)

[2](#fs.path.type.cvt-2)

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

For member function arguments that take character sequences representing
paths and for member functions returning strings, value type and encoding
conversion is performed if the value type of the argument or return value differs frompath​::​value_type[.](#fs.path.type.cvt-2.sentence-1)

For the argument or return value, the method of conversion and the encoding
to be converted to is determined
by its value type:

- [(2.1)](#fs.path.type.cvt-2.1)

  char: The encoding is the native ordinary encoding[.](#fs.path.type.cvt-2.1.sentence-1)
  The method of conversion, if any, is operating system dependent[.](#fs.path.type.cvt-2.1.sentence-2)
  [*Note [1](#fs.path.type.cvt-note-1)*:
  For POSIX-based operating systems path​::​value_type is char so no conversion from char value type arguments or to char value type return values is performed[.](#fs.path.type.cvt-2.1.sentence-3)
  For Windows-based operating systems, the
native ordinary encoding is determined by calling a Windows API function[.](#fs.path.type.cvt-2.1.sentence-4)
 â *end note*]
  [*Note [2](#fs.path.type.cvt-note-2)*:
  This results in behavior identical to other C and C++
standard library functions that perform file operations using ordinary character
strings to identify paths[.](#fs.path.type.cvt-2.1.sentence-5)
  Changing this behavior would be surprising and
error-prone[.](#fs.path.type.cvt-2.1.sentence-6)
 â *end note*]

- [(2.2)](#fs.path.type.cvt-2.2)

  wchar_t: The encoding is the native wide encoding[.](#fs.path.type.cvt-2.2.sentence-1)
  The method of conversion is unspecified[.](#fs.path.type.cvt-2.2.sentence-2)
  [*Note [3](#fs.path.type.cvt-note-3)*:
  For Windows-based operating systems path​::​value_type is wchar_t so no conversion from wchar_t value type arguments or to wchar_t value type return values is performed[.](#fs.path.type.cvt-2.2.sentence-3)
 â *end note*]

- [(2.3)](#fs.path.type.cvt-2.3)

  char8_t: The encoding is UTF-8[.](#fs.path.type.cvt-2.3.sentence-1)
  The method of conversion
is unspecified[.](#fs.path.type.cvt-2.3.sentence-2)

- [(2.4)](#fs.path.type.cvt-2.4)

  char16_t: The encoding is UTF-16[.](#fs.path.type.cvt-2.4.sentence-1)
  The method of conversion
is unspecified[.](#fs.path.type.cvt-2.4.sentence-2)

- [(2.5)](#fs.path.type.cvt-2.5)

  char32_t: The encoding is UTF-32[.](#fs.path.type.cvt-2.5.sentence-1)
  The method of conversion
is unspecified[.](#fs.path.type.cvt-2.5.sentence-2)

[3](#fs.path.type.cvt-3)

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

If the encoding being converted to has no representation for source
characters, the resulting converted characters, if any, are unspecified[.](#fs.path.type.cvt-3.sentence-1)

Implementations should not modify member function arguments
if already of type path​::​value_type[.](#fs.path.type.cvt-3.sentence-2)

#### [31.12.6.4](#fs.path.req) Requirements [[fs.path.req]](fs.path.req)

[1](#fs.path.req-1)

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

In addition to the requirements ([[fs.req]](#fs.req "31.12.3 Requirements")),
function template parameters named Source shall be one of:

- [(1.1)](#fs.path.req-1.1)

  basic_string<EcharT, traits, Allocator>[.](#fs.path.req-1.1.sentence-1)
  A function
 argument const Source& source shall have an
 effective range [source.begin(), source.end())[.](#fs.path.req-1.1.sentence-2)

- [(1.2)](#fs.path.req-1.2)

  basic_string_view<EcharT, traits>[.](#fs.path.req-1.2.sentence-1)
  A function
 argument const Source& source shall have an
 effective range [source.begin(), source.end())[.](#fs.path.req-1.2.sentence-2)

- [(1.3)](#fs.path.req-1.3)

  A type meeting the [*Cpp17InputIterator*](input.iterators#:Cpp17InputIterator "24.3.5.3 Input iterators [input.iterators]") requirements that iterates over an NTCTS[.](#fs.path.req-1.3.sentence-1)
  The value type shall be an encoded character type[.](#fs.path.req-1.3.sentence-2)
  A function argument const Source& source shall have an effective range
 [source, end) where end is the first
 iterator value with an element value equal to iterator_traits<Source>​::​value_type()[.](#fs.path.req-1.3.sentence-3)

- [(1.4)](#fs.path.req-1.4)

  A character array that after array-to-pointer decay results in a
 pointer to the start of an NTCTS[.](#fs.path.req-1.4.sentence-1)
  The value type shall be an encoded character type[.](#fs.path.req-1.4.sentence-2)
  A
 function argument const Source& source shall
 have an effective range [source, end) where end is the first iterator value with an element value equal to iterator_traits<decay_t<Source>>​::​value_type()[.](#fs.path.req-1.4.sentence-3)

[2](#fs.path.req-2)

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

Functions taking template parameters named Source shall not participate in overload resolution unlessSource denotes a type other than path, and
either

- [(2.1)](#fs.path.req-2.1)

Source is a specialization ofbasic_string or basic_string_view, or

- [(2.2)](#fs.path.req-2.2)

the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3 Qualified names [expr.prim.id.qual]") iterator_traits<decay_t<Source>>​::​value_type is valid and
denotes a possibly const encoded character type ([[temp.deduct]](temp.deduct "13.10.3 Template argument deduction"))[.](#fs.path.req-2.sentence-1)

[3](#fs.path.req-3)

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

[*Note [1](#fs.path.req-note-1)*:

See [path conversions](#fs.path.cvt "31.12.6.3 Conversions [fs.path.cvt]") for how the value types above and their encodings convert topath​::​value_type and its encoding[.](#fs.path.req-3.sentence-1)

â *end note*]

[4](#fs.path.req-4)

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

Arguments of type Source shall not be null pointers[.](#fs.path.req-4.sentence-1)

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

#### [31.12.6.5.1](#fs.path.construct) Constructors [[fs.path.construct]](fs.path.construct)

[ð](#lib:path,constructor)

`path() noexcept;
`

[1](#fs.path.construct-1)

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

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

[ð](#lib:path,constructor_)

`path(const path& p);
path(path&& p) noexcept;
`

[2](#fs.path.construct-2)

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

*Effects*: Constructs an object of class path having the same pathname in the native and generic formats, respectively,
as the original value of p[.](#fs.path.construct-2.sentence-1)

In the second form, p is left in a valid but unspecified state[.](#fs.path.construct-2.sentence-2)

[ð](#lib:path,constructor__)

`path(string_type&& source, format fmt = auto_format);
`

[3](#fs.path.construct-3)

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

*Effects*: Constructs an object of class path for which the pathname in the detected-format of source has the original value of source ([[fs.path.fmt.cvt]](#fs.path.fmt.cvt "31.12.6.3.1 Argument format conversions")),
converting format if required ([[fs.path.fmt.cvt]](#fs.path.fmt.cvt "31.12.6.3.1 Argument format conversions"))[.](#fs.path.construct-3.sentence-1)

source is left in a valid but unspecified state[.](#fs.path.construct-3.sentence-2)

[ð](#lib:path,constructor___)

`template<class Source>
  path(const Source& source, format fmt = auto_format);
template<class InputIterator>
  path(InputIterator first, InputIterator last, format fmt = auto_format);
`

[4](#fs.path.construct-4)

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

*Effects*: Let s be the effective range of source ([[fs.path.req]](#fs.path.req "31.12.6.4 Requirements"))
or the range [first, last), with the encoding converted if required ([[fs.path.cvt]](#fs.path.cvt "31.12.6.3 Conversions"))[.](#fs.path.construct-4.sentence-1)

Finds the detected-format of s ([[fs.path.fmt.cvt]](#fs.path.fmt.cvt "31.12.6.3.1 Argument format conversions"))
and constructs an object of class path for which the pathname in that format is s[.](#fs.path.construct-4.sentence-2)

[ð](#lib:path,constructor____)

`template<class Source>
  path(const Source& source, const locale& loc, format fmt = auto_format);
template<class InputIterator>
  path(InputIterator first, InputIterator last, const locale& loc, format fmt = auto_format);
`

[5](#fs.path.construct-5)

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

*Mandates*: The value type of Source and InputIterator ischar[.](#fs.path.construct-5.sentence-1)

[6](#fs.path.construct-6)

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

*Effects*: Let s be the effective range of source or the range [first, last),
after converting the encoding as
follows:

- [(6.1)](#fs.path.construct-6.1)

  If value_type is wchar_t, converts to the native
wide encoding ([[fs.path.type.cvt]](#fs.path.type.cvt "31.12.6.3.2 Type and encoding conversions")) using the codecvt<​wchar_t, char, mbstate_t> facet of loc[.](#fs.path.construct-6.1.sentence-1)

- [(6.2)](#fs.path.construct-6.2)

  Otherwise a conversion is performed using thecodecvt<wchar_t, char, mbstate_t> facet of loc, and then a second
conversion to the current ordinary encoding[.](#fs.path.construct-6.2.sentence-1)

[7](#fs.path.construct-7)

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

Finds the detected-format of s ([[fs.path.fmt.cvt]](#fs.path.fmt.cvt "31.12.6.3.1 Argument format conversions"))
and constructs an object of class path for which the pathname in that format is s[.](#fs.path.construct-7.sentence-1)

[*Example [1](#fs.path.construct-example-1)*:

A string is to be read from a database
that is encoded in ISO/IEC 8859-1, and used to create a directory:namespace fs = std::filesystem;
std::string latin1_string = read_latin1_data();
codecvt_8859_1<wchar_t> latin1_facet;
std::locale latin1_locale(std::locale(), latin1_facet);
fs::create_directory(fs::path(latin1_string, latin1_locale));

For POSIX-based operating systems, the path is constructed by first usinglatin1_facet to convert ISO/IEC 8859-1 encodedlatin1_string to a wide character string in the native wide
encoding ([[fs.path.type.cvt]](#fs.path.type.cvt "31.12.6.3.2 Type and encoding conversions"))[.](#fs.path.construct-7.sentence-3)

The resulting wide string is then
converted to an ordinary character
pathname string in the current native ordinary encoding[.](#fs.path.construct-7.sentence-4)

If the
native wide encoding is UTF-16 or UTF-32, and the current native ordinary
encoding is UTF-8, all of the characters in the ISO/IEC 8859-1 character set
will be converted to their Unicode representation, but for other native
ordinary encodings some characters may have no representation[.](#fs.path.construct-7.sentence-5)

For Windows-based operating systems, the path is constructed by
using latin1_facet to convert ISO/IEC 8859-1 encodedlatin1_string to a UTF-16 encoded wide character pathname
string[.](#fs.path.construct-7.sentence-6)

All of the characters in the ISO/IEC 8859-1 character set will be
converted to their Unicode representation[.](#fs.path.construct-7.sentence-7)

â *end example*]

#### [31.12.6.5.2](#fs.path.assign) Assignments [[fs.path.assign]](fs.path.assign)

[ð](#lib:operator=,path)

`path& operator=(const path& p);
`

[1](#fs.path.assign-1)

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

*Effects*: If *this and p are the same
object, has no effect[.](#fs.path.assign-1.sentence-1)

Otherwise,
sets both respective pathnames of *this to the respective pathnames of p[.](#fs.path.assign-1.sentence-2)

[2](#fs.path.assign-2)

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

*Returns*: *this[.](#fs.path.assign-2.sentence-1)

[ð](#lib:operator=,path_)

`path& operator=(path&& p) noexcept;
`

[3](#fs.path.assign-3)

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

*Effects*: If *this and p are the same
object, has no effect[.](#fs.path.assign-3.sentence-1)

Otherwise,
sets both respective pathnames of *this to the respective pathnames of p[.](#fs.path.assign-3.sentence-2)

p is left in a valid but unspecified state[.](#fs.path.assign-3.sentence-3)

[*Note [1](#fs.path.assign-note-1)*:

A valid implementation is swap(p)[.](#fs.path.assign-3.sentence-4)

â *end note*]

[4](#fs.path.assign-4)

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

*Returns*: *this[.](#fs.path.assign-4.sentence-1)

[ð](#lib:operator=,path__)

`path& operator=(string_type&& source);
path& assign(string_type&& source);
`

[5](#fs.path.assign-5)

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

*Effects*: Sets the pathname in the detected-format of source to the original value of source[.](#fs.path.assign-5.sentence-1)

source is left in a valid but unspecified state[.](#fs.path.assign-5.sentence-2)

[6](#fs.path.assign-6)

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

*Returns*: *this[.](#fs.path.assign-6.sentence-1)

[ð](#lib:operator=,path___)

`template<class Source>
  path& operator=(const Source& source);
template<class Source>
  path& assign(const Source& source);
template<class InputIterator>
  path& assign(InputIterator first, InputIterator last);
`

[7](#fs.path.assign-7)

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

*Effects*: Let s be the effective range of source ([[fs.path.req]](#fs.path.req "31.12.6.4 Requirements"))
or the range [first, last), with the encoding converted if required ([[fs.path.cvt]](#fs.path.cvt "31.12.6.3 Conversions"))[.](#fs.path.assign-7.sentence-1)

Finds the detected-format of s ([[fs.path.fmt.cvt]](#fs.path.fmt.cvt "31.12.6.3.1 Argument format conversions"))
and sets the pathname in that format to s[.](#fs.path.assign-7.sentence-2)

[8](#fs.path.assign-8)

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

*Returns*: *this[.](#fs.path.assign-8.sentence-1)

#### [31.12.6.5.3](#fs.path.append) Appends [[fs.path.append]](fs.path.append)

[1](#fs.path.append-1)

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

The append operations use operator/= to denote their semantic effect of appending[*preferred-separator*](#nt:preferred-separator "31.12.6.2 Generic pathname format [fs.path.generic]") when needed[.](#fs.path.append-1.sentence-1)

[ð](#lib:operator/=,path)

`path& operator/=(const path& p);
`

[2](#fs.path.append-2)

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

*Effects*: If p.is_absolute() || (p.has_root_name() && p.root_name() != root_name()),
then operator=(p)[.](#fs.path.append-2.sentence-1)

[3](#fs.path.append-3)

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

Otherwise, modifies *this as if by these steps:

- [(3.1)](#fs.path.append-3.1)

  If p.has_root_directory(),
 then removes any root directory and relative path
 from the generic format pathname[.](#fs.path.append-3.1.sentence-1)
  Otherwise,
 if !has_root_directory() && is_absolute() is true or if has_filename() is true,
 then appends path​::​preferred_separator to the generic format pathname[.](#fs.path.append-3.1.sentence-2)

- [(3.2)](#fs.path.append-3.2)

  Then appends the native format pathname of p,
 omitting any [*root-name*](#nt:root-name "31.12.6.2 Generic pathname format [fs.path.generic]") from its generic format pathname,
 to the native format pathname[.](#fs.path.append-3.2.sentence-1)

[4](#fs.path.append-4)

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

[*Example [1](#fs.path.append-example-1)*:

Even if //host is interpreted as a [*root-name*](#nt:root-name "31.12.6.2 Generic pathname format [fs.path.generic]"),
both of the paths path("//host")/"foo" and path("//host/")/"foo" equal "//host/foo" (although the former might use backslash as the
preferred separator)[.](#fs.path.append-4.sentence-1)

Expression examples:// On POSIX, path("foo") /= path(""); // yields path("foo/") path("foo") /= path("/bar"); // yields path("/bar")// On Windows, path("foo") /= path(""); // yields path("foo\\") path("foo") /= path("/bar"); // yields path("/bar") path("foo") /= path("c:/bar"); // yields path("c:/bar") path("foo") /= path("c:"); // yields path("c:") path("c:") /= path(""); // yields path("c:") path("c:foo") /= path("/bar"); // yields path("c:/bar") path("c:foo") /= path("c:bar"); // yields path("c:foo\\bar")

â *end example*]

[5](#fs.path.append-5)

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

*Returns*: *this[.](#fs.path.append-5.sentence-1)

[ð](#lib:operator/=,path_)

`template<class Source>
  path& operator/=(const Source& source);
template<class Source>
  path& append(const Source& source);
`

[6](#fs.path.append-6)

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

*Effects*: Equivalent to: return operator/=(path(source));

[ð](#lib:operator/=,path__)

`template<class InputIterator>
  path& append(InputIterator first, InputIterator last);
`

[7](#fs.path.append-7)

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

*Effects*: Equivalent to: return operator/=(path(first, last));

#### [31.12.6.5.4](#fs.path.concat) Concatenation [[fs.path.concat]](fs.path.concat)

[ð](#lib:operator+=,path)

`path& operator+=(const path& x);
path& operator+=(const string_type& x);
path& operator+=(basic_string_view<value_type> x);
path& operator+=(const value_type* x);
template<class Source>
  path& operator+=(const Source& x);
template<class Source>
  path& concat(const Source& x);
`

[1](#fs.path.concat-1)

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

*Effects*: Appends path(x).native() to the pathname in the native format[.](#fs.path.concat-1.sentence-1)

[*Note [1](#fs.path.concat-note-1)*:

This directly manipulates the value of native(),
which is not necessarily portable between operating systems[.](#fs.path.concat-1.sentence-2)

â *end note*]

[2](#fs.path.concat-2)

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

*Returns*: *this[.](#fs.path.concat-2.sentence-1)

[ð](#lib:operator+=,path_)

`path& operator+=(value_type x);
template<class EcharT>
  path& operator+=(EcharT x);
`

[3](#fs.path.concat-3)

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

*Effects*: Equivalent to: return *this += basic_string_view(&x, 1);

[ð](#lib:concat,path__)

`template<class InputIterator>
  path& concat(InputIterator first, InputIterator last);
`

[4](#fs.path.concat-4)

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

*Effects*: Equivalent to: return *this += path(first, last);

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

[ð](#lib:clear,path)

`void clear() noexcept;
`

[1](#fs.path.modifiers-1)

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

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

[ð](#lib:make_preferred,path)

`path& make_preferred();
`

[2](#fs.path.modifiers-2)

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

*Effects*: Each [*directory-separator*](#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*](#nt:preferred-separator "31.12.6.2 Generic pathname format [fs.path.generic]")[.](#fs.path.modifiers-2.sentence-1)

[3](#fs.path.modifiers-3)

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

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

[4](#fs.path.modifiers-4)

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

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

On an operating system where [*preferred-separator*](#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*](#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](#fs.path.modifiers-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[.](#fs.path.modifiers-5.sentence-1)

[6](#fs.path.modifiers-6)

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

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

[7](#fs.path.modifiers-7)

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

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

[8](#fs.path.modifiers-8)

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

[*Example [2](#fs.path.modifiers-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](#fs.path.modifiers-9)

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

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

[10](#fs.path.modifiers-10)

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

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

[11](#fs.path.modifiers-11)

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

[*Example [3](#fs.path.modifiers-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](#fs.path.modifiers-12)

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

*Effects*: 

- [(12.1)](#fs.path.modifiers-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)](#fs.path.modifiers-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)](#fs.path.modifiers-12.3)

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

[13](#fs.path.modifiers-13)

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

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

[ð](#lib:swap,path)

`void swap(path& rhs) noexcept;
`

[14](#fs.path.modifiers-14)

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

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

[15](#fs.path.modifiers-15)

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

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

#### [31.12.6.5.6](#fs.path.native.obs) Native format observers [[fs.path.native.obs]](fs.path.native.obs)

[1](#fs.path.native.obs-1)

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

The string returned by all native format observers is in the native pathname format ([[fs.class.path]](#fs.class.path "31.12.6 Class path"))[.](#fs.path.native.obs-1.sentence-1)

[ð](#lib:native,path)

`const string_type& native() const noexcept;
`

[2](#fs.path.native.obs-2)

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

*Returns*: The pathname in the native format[.](#fs.path.native.obs-2.sentence-1)

[ð](#lib:c_str,path)

`const value_type* c_str() const noexcept;
`

[3](#fs.path.native.obs-3)

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

*Effects*: Equivalent to: return native().c_str();

[ð](#lib:operator_string_type,path)

`operator string_type() const;
`

[4](#fs.path.native.obs-4)

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

*Returns*: native()[.](#fs.path.native.obs-4.sentence-1)

[ð](#lib:string,path)

`template<class EcharT, class traits = char_traits<EcharT>, class Allocator = allocator<EcharT>>
  basic_string<EcharT, traits, Allocator> string(const Allocator& a = Allocator()) const;
`

[5](#fs.path.native.obs-5)

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

*Returns*: native()[.](#fs.path.native.obs-5.sentence-1)

[6](#fs.path.native.obs-6)

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

*Remarks*: All memory allocation, including for the return value, shall
be performed by a[.](#fs.path.native.obs-6.sentence-1)

Conversion, if any, is specified by[[fs.path.cvt]](#fs.path.cvt "31.12.6.3 Conversions")[.](#fs.path.native.obs-6.sentence-2)

[ð](#lib:system_encoded_string,path)

`std::string system_encoded_string() const;
std::wstring wstring() const;
std::u8string u8string() const;
std::u16string u16string() const;
std::u32string u32string() const;
`

[7](#fs.path.native.obs-7)

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

*Returns*: native()[.](#fs.path.native.obs-7.sentence-1)

[8](#fs.path.native.obs-8)

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

*Remarks*: Conversion, if any, is performed as specified
by [[fs.path.cvt]](#fs.path.cvt "31.12.6.3 Conversions")[.](#fs.path.native.obs-8.sentence-1)

[ð](#lib:display_string,path)

`std::string display_string() const;
`

[9](#fs.path.native.obs-9)

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

*Returns*: format("{}", *this)[.](#fs.path.native.obs-9.sentence-1)

[*Note [1](#fs.path.native.obs-note-1)*:

The returned string is suitable for use with formatting ([[format.functions]](format.functions "28.5.5 Formatting functions"))
and print functions ([[print.fun]](print.fun "31.7.10 Print functions"))[.](#fs.path.native.obs-9.sentence-2)

â *end note*]

#### [31.12.6.5.7](#fs.path.generic.obs) Generic format observers [[fs.path.generic.obs]](fs.path.generic.obs)

[1](#fs.path.generic.obs-1)

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

Generic format observer functions return strings formatted according to the[generic pathname format](#fs.path.generic "31.12.6.2 Generic pathname format [fs.path.generic]")[.](#fs.path.generic.obs-1.sentence-1)

A single slash ('/') character is used as
the [*directory-separator*](#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]")[.](#fs.path.generic.obs-1.sentence-2)

[2](#fs.path.generic.obs-2)

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

[*Example [1](#fs.path.generic.obs-example-1)*:

On an operating system that uses backslash as
its [*preferred-separator*](#nt:preferred-separator "31.12.6.2 Generic pathname format [fs.path.generic]"),path("foo\\bar").generic_string() returns "foo/bar"[.](#fs.path.generic.obs-2.sentence-1)

â *end example*]

[ð](#lib:generic_string,path)

`template<class EcharT, class traits = char_traits<EcharT>, class Allocator = allocator<EcharT>>
  basic_string<EcharT, traits, Allocator> generic_string(const Allocator& a = Allocator()) const;
`

[3](#fs.path.generic.obs-3)

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

*Returns*: The pathname in the generic format[.](#fs.path.generic.obs-3.sentence-1)

[4](#fs.path.generic.obs-4)

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

*Remarks*: All memory allocation, including for the return value, shall
be performed by a[.](#fs.path.generic.obs-4.sentence-1)

Conversion, if any, is specified by[[fs.path.cvt]](#fs.path.cvt "31.12.6.3 Conversions")[.](#fs.path.generic.obs-4.sentence-2)

[ð](#lib:generic_system_encoded_string,path)

`std::string generic_system_encoded_string() const;
std::wstring generic_wstring() const;
std::u8string generic_u8string() const;
std::u16string generic_u16string() const;
std::u32string generic_u32string() const;
`

[5](#fs.path.generic.obs-5)

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

*Returns*: The pathname in the generic format[.](#fs.path.generic.obs-5.sentence-1)

[6](#fs.path.generic.obs-6)

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

*Remarks*: Conversion, if any, is specified by [[fs.path.cvt]](#fs.path.cvt "31.12.6.3 Conversions")[.](#fs.path.generic.obs-6.sentence-1)

[ð](#lib:generic_display_string,path)

`std::string generic_display_string() const;
`

[7](#fs.path.generic.obs-7)

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

*Returns*: format("{:g}", *this)[.](#fs.path.generic.obs-7.sentence-1)

[*Note [1](#fs.path.generic.obs-note-1)*:

The returned string is suitable for use with formatting ([[format.functions]](format.functions "28.5.5 Formatting functions"))
and print functions ([[print.fun]](print.fun "31.7.10 Print functions"))[.](#fs.path.generic.obs-7.sentence-2)

â *end note*]

#### [31.12.6.5.8](#fs.path.compare) Compare [[fs.path.compare]](fs.path.compare)

[ð](#lib:compare,path)

`int compare(const path& p) const noexcept;
`

[1](#fs.path.compare-1)

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

*Returns*: 

- [(1.1)](#fs.path.compare-1.1)

  Let rootNameComparison be the result of this->root_name().native().compare(p.root_name().native())[.](#fs.path.compare-1.1.sentence-1)
  If rootNameComparison is not 0, rootNameComparison[.](#fs.path.compare-1.1.sentence-2)

- [(1.2)](#fs.path.compare-1.2)

  Otherwise, if !this->has_root_directory() and p.has_root_directory(),
 a value less than 0[.](#fs.path.compare-1.2.sentence-1)

- [(1.3)](#fs.path.compare-1.3)

  Otherwise, if this->has_root_directory() and !p.has_root_directory(),
 a value greater than 0[.](#fs.path.compare-1.3.sentence-1)

- [(1.4)](#fs.path.compare-1.4)

  Otherwise, if native() for the elements of this->relative_path() are lexicographically less than native() for the elements of p.relative_path(),
 a value less than 0[.](#fs.path.compare-1.4.sentence-1)

- [(1.5)](#fs.path.compare-1.5)

  Otherwise, if native() for the elements of this->relative_path() are lexicographically greater than native() for the elements of p.relative_path(),
 a value greater than 0[.](#fs.path.compare-1.5.sentence-1)

- [(1.6)](#fs.path.compare-1.6)

  Otherwise, 0[.](#fs.path.compare-1.6.sentence-1)

[ð](#lib:compare,path_)

`int compare(const string_type& s) const;
int compare(basic_string_view<value_type> s) const;
int compare(const value_type* s) const;
`

[2](#fs.path.compare-2)

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

*Effects*: Equivalent to: return compare(path(s));

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

[ð](#lib:root_name,path)

`path root_name() const;
`

[1](#fs.path.decompose-1)

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

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

[ð](#lib:root_directory,path)

`path root_directory() const;
`

[2](#fs.path.decompose-2)

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

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

[ð](#lib:root_path,path)

`path root_path() const;
`

[3](#fs.path.decompose-3)

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

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

[ð](#lib:relative_path,path)

`path relative_path() const;
`

[4](#fs.path.decompose-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*](#nt:filename "31.12.6.2 Generic pathname format [fs.path.generic]") after root_path()[.](#fs.path.decompose-4.sentence-1)

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

[ð](#lib:parent_path,path)

`path parent_path() const;
`

[5](#fs.path.decompose-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[.](#fs.path.decompose-5.sentence-1)

[ð](#lib:filename,path)

`path filename() const;
`

[6](#fs.path.decompose-6)

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

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

[7](#fs.path.decompose-7)

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

[*Example [1](#fs.path.decompose-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](#fs.path.decompose-8)

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

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

Returns a path whose pathname in the generic format is

- [(8.1)](#fs.path.decompose-8.1)

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

- [(8.2)](#fs.path.decompose-8.2)

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

[9](#fs.path.decompose-9)

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

[*Example [2](#fs.path.decompose-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](#fs.path.decompose-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()[.](#fs.path.decompose-10.sentence-1)

[11](#fs.path.decompose-11)

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

[*Example [3](#fs.path.decompose-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](#fs.path.decompose-12)

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

[*Note [1](#fs.path.decompose-note-1)*:

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

â *end note*]

[13](#fs.path.decompose-13)

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

[*Note [2](#fs.path.decompose-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[.](#fs.path.decompose-13.sentence-1)

â *end note*]

#### [31.12.6.5.10](#fs.path.query) Query [[fs.path.query]](fs.path.query)

[ð](#lib:empty,path)

`bool empty() const noexcept;
`

[1](#fs.path.query-1)

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

*Returns*: true if the pathname in the generic format is empty, otherwise false[.](#fs.path.query-1.sentence-1)

[ð](#lib:has_root_path,path)

`bool has_root_path() const;
`

[2](#fs.path.query-2)

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

*Returns*: !root_path().empty()[.](#fs.path.query-2.sentence-1)

[ð](#lib:has_root_name,path)

`bool has_root_name() const;
`

[3](#fs.path.query-3)

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

*Returns*: !root_name().empty()[.](#fs.path.query-3.sentence-1)

[ð](#lib:has_root_directory,path)

`bool has_root_directory() const;
`

[4](#fs.path.query-4)

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

*Returns*: !root_directory().empty()[.](#fs.path.query-4.sentence-1)

[ð](#lib:has_relative_path,path)

`bool has_relative_path() const;
`

[5](#fs.path.query-5)

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

*Returns*: !relative_path().empty()[.](#fs.path.query-5.sentence-1)

[ð](#lib:has_parent_path,path)

`bool has_parent_path() const;
`

[6](#fs.path.query-6)

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

*Returns*: !parent_path().empty()[.](#fs.path.query-6.sentence-1)

[ð](#lib:has_filename,path)

`bool has_filename() const;
`

[7](#fs.path.query-7)

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

*Returns*: !filename().empty()[.](#fs.path.query-7.sentence-1)

[ð](#lib:has_stem,path)

`bool has_stem() const;
`

[8](#fs.path.query-8)

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

*Returns*: !stem().empty()[.](#fs.path.query-8.sentence-1)

[ð](#lib:has_extension,path)

`bool has_extension() const;
`

[9](#fs.path.query-9)

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

*Returns*: !extension().empty()[.](#fs.path.query-9.sentence-1)

[ð](#lib:is_absolute,path)

`bool is_absolute() const;
`

[10](#fs.path.query-10)

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

*Returns*: true if the pathname in the native format
 contains an absolute path ([[fs.class.path]](#fs.class.path "31.12.6 Class path")), otherwise false[.](#fs.path.query-10.sentence-1)

[11](#fs.path.query-11)

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

[*Example [1](#fs.path.query-example-1)*:

path("/").is_absolute() is true for POSIX-based operating systems, and false for Windows-based
operating systems[.](#fs.path.query-11.sentence-1)

â *end example*]

[ð](#lib:is_relative,path)

`bool is_relative() const;
`

[12](#fs.path.query-12)

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

*Returns*: !is_absolute()[.](#fs.path.query-12.sentence-1)

#### [31.12.6.5.11](#fs.path.gen) Generation [[fs.path.gen]](fs.path.gen)

[ð](#lib:lexically_normal,path)

`path lexically_normal() const;
`

[1](#fs.path.gen-1)

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

*Returns*: A path whose pathname in the generic format is
the normal form ([[fs.path.generic]](#fs.path.generic "31.12.6.2 Generic pathname format")) of the pathname
in the generic format of *this[.](#fs.path.gen-1.sentence-1)

[2](#fs.path.gen-2)

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

[*Example [1](#fs.path.gen-example-1)*: assert(path("foo/./bar/..").lexically_normal() == "foo/");
assert(path("foo/.///bar/../").lexically_normal() == "foo/");

The above assertions will succeed[.](#fs.path.gen-2.sentence-1)

On Windows, the returned path's [*directory-separator*](#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]") characters
will be backslashes rather than slashes,
but that does not affect path equality[.](#fs.path.gen-2.sentence-2)

â *end example*]

[ð](#lib:lexically_relative,path)

`path lexically_relative(const path& base) const;
`

[3](#fs.path.gen-3)

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

*Effects*: If:

- [(3.1)](#fs.path.gen-3.1)

root_name() != base.root_name() is true, or

- [(3.2)](#fs.path.gen-3.2)

is_absolute() != base.is_absolute() is true, or

- [(3.3)](#fs.path.gen-3.3)

!has_root_directory() && base.has_root_directory() is true, or

- [(3.4)](#fs.path.gen-3.4)

any [*filename*](#nt:filename "31.12.6.2 Generic pathname format [fs.path.generic]") inrelative_path() or base.relative_path() can be interpreted as a [*root-name*](#nt:root-name "31.12.6.2 Generic pathname format [fs.path.generic]"),

returns path()[.](#fs.path.gen-3.sentence-1)

[*Note [1](#fs.path.gen-note-1)*:

On a POSIX implementation, no [*filename*](#nt:filename "31.12.6.2 Generic pathname format [fs.path.generic]") in a [*relative-path*](#nt:relative-path "31.12.6.2 Generic pathname format [fs.path.generic]") is acceptable as a [*root-name*](#nt:root-name "31.12.6.2 Generic pathname format [fs.path.generic]")[.](#fs.path.gen-3.sentence-2)

â *end note*]

Determines the first mismatched element of *this and base as if by:auto [a, b] = mismatch(begin(), end(), base.begin(), base.end());

Then,

- [(3.5)](#fs.path.gen-3.5)

  if a == end() and b == base.end(), returns path("."); otherwise

- [(3.6)](#fs.path.gen-3.6)

  let n be the number of [*filename*](#nt:filename "31.12.6.2 Generic pathname format [fs.path.generic]") elements in [b, base.end())
 that are not dot or dot-dot or empty, minus the number that are dot-dot[.](#fs.path.gen-3.6.sentence-1)
  If n<0, returns path(); otherwise

- [(3.7)](#fs.path.gen-3.7)

  if n == 0 and (a == end() || a->empty()),
 returns path("."); otherwise

- [(3.8)](#fs.path.gen-3.8)

  returns an object of class path that is default-constructed, followed by
  * [(3.8.1)](#fs.path.gen-3.8.1)

application of operator/=(path(".."))n times, and then

  * [(3.8.2)](#fs.path.gen-3.8.2)

application of operator/= for each element in [a, end())[.](#fs.path.gen-3.8.sentence-1)

[4](#fs.path.gen-4)

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

*Returns*: *this made relative to base[.](#fs.path.gen-4.sentence-1)

Does not resolve ([[fs.class.path]](#fs.class.path "31.12.6 Class path")) symlinks[.](#fs.path.gen-4.sentence-2)

Does not first normalize ([[fs.path.generic]](#fs.path.generic "31.12.6.2 Generic pathname format")) *this or base[.](#fs.path.gen-4.sentence-3)

[5](#fs.path.gen-5)

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

[*Example [2](#fs.path.gen-example-2)*: assert(path("/a/d").lexically_relative("/a/b/c") == "../../d");
assert(path("/a/b/c").lexically_relative("/a/d") == "../b/c");
assert(path("a/b/c").lexically_relative("a") == "b/c");
assert(path("a/b/c").lexically_relative("a/b/c/x/y") == "../..");
assert(path("a/b/c").lexically_relative("a/b/c") == ".");
assert(path("a/b").lexically_relative("c/d") == "../../a/b");

The above assertions will succeed[.](#fs.path.gen-5.sentence-1)

On Windows, the returned path's [*directory-separator*](#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]") characters
will be backslashes rather than slashes,
but that does not affect path equality[.](#fs.path.gen-5.sentence-2)

â *end example*]

[6](#fs.path.gen-6)

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

[*Note [2](#fs.path.gen-note-2)*:

If symlink following semantics are desired,
 use the operational function relative()[.](#fs.path.gen-6.sentence-1)

â *end note*]

[7](#fs.path.gen-7)

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

[*Note [3](#fs.path.gen-note-3)*:

If normalization ([[fs.path.generic]](#fs.path.generic "31.12.6.2 Generic pathname format")) is needed
 to ensure consistent matching of elements,
 apply lexically_normal() to *this, base, or both[.](#fs.path.gen-7.sentence-1)

â *end note*]

[ð](#lib:lexically_proximate,path)

`path lexically_proximate(const path& base) const;
`

[8](#fs.path.gen-8)

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

*Returns*: If the value of lexically_relative(base) is not an empty path,
 return it[.](#fs.path.gen-8.sentence-1)

Otherwise return *this[.](#fs.path.gen-8.sentence-2)

[9](#fs.path.gen-9)

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

[*Note [4](#fs.path.gen-note-4)*:

If symlink following semantics are desired,
 use the operational function proximate()[.](#fs.path.gen-9.sentence-1)

â *end note*]

[10](#fs.path.gen-10)

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

[*Note [5](#fs.path.gen-note-5)*:

If normalization ([[fs.path.generic]](#fs.path.generic "31.12.6.2 Generic pathname format")) is needed
 to ensure consistent matching of elements,
 apply lexically_normal() to *this, base, or both[.](#fs.path.gen-10.sentence-1)

â *end note*]

#### [31.12.6.6](#fs.path.itr) Iterators [[fs.path.itr]](fs.path.itr)

[1](#fs.path.itr-1)

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

Path iterators iterate over the elements of the pathname
in the [generic format](#fs.path.generic "31.12.6.2 Generic pathname format [fs.path.generic]")[.](#fs.path.itr-1.sentence-1)

[2](#fs.path.itr-2)

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

A path​::​iterator is a constant iterator meeting all the
requirements of a [bidirectional iterator](bidirectional.iterators "24.3.5.6 Bidirectional iterators [bidirectional.iterators]") except that,
for dereferenceable iterators a and b of type path​::​iterator with a == b,
there is no requirement that *a and *b are bound to the same object[.](#fs.path.itr-2.sentence-1)

Its value_type is path[.](#fs.path.itr-2.sentence-2)

[3](#fs.path.itr-3)

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

Calling any non-const member function of a path object
invalidates all iterators referring to elements of that object[.](#fs.path.itr-3.sentence-1)

[4](#fs.path.itr-4)

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

For the elements of the pathname in the generic format,
the forward traversal order is as follows:

- [(4.1)](#fs.path.itr-4.1)

  The [*root-name*](#nt:root-name "31.12.6.2 Generic pathname format [fs.path.generic]") element, if present[.](#fs.path.itr-4.1.sentence-1)

- [(4.2)](#fs.path.itr-4.2)

  The [*root-directory*](#nt:root-directory "31.12.6.2 Generic pathname format [fs.path.generic]") element, if present[.](#fs.path.itr-4.2.sentence-1)
  [*Note [1](#fs.path.itr-note-1)*:
  It is possible that the use of the generic format is needed
to ensure correct lexicographical comparison[.](#fs.path.itr-4.2.sentence-2)
 â *end note*]

- [(4.3)](#fs.path.itr-4.3)

  Each successive [*filename*](#nt:filename "31.12.6.2 Generic pathname format [fs.path.generic]") element, if present[.](#fs.path.itr-4.3.sentence-1)

- [(4.4)](#fs.path.itr-4.4)

  An empty element, if a trailing non-root [*directory-separator*](#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]") is present[.](#fs.path.itr-4.4.sentence-1)

[5](#fs.path.itr-5)

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

The backward traversal order is the reverse of forward traversal[.](#fs.path.itr-5.sentence-1)

[ð](#lib:begin,path)

`iterator begin() const;
`

[6](#fs.path.itr-6)

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

*Returns*: An iterator for the first present element in the traversal
list above[.](#fs.path.itr-6.sentence-1)

If no elements are present, the end iterator[.](#fs.path.itr-6.sentence-2)

[ð](#lib:end,path)

`iterator end() const;
`

[7](#fs.path.itr-7)

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

*Returns*: The end iterator[.](#fs.path.itr-7.sentence-1)

#### [31.12.6.7](#fs.path.io) Inserter and extractor [[fs.path.io]](fs.path.io)

[ð](#lib:operator%3c%3c,path)

`template<class charT, class traits>
  friend basic_ostream<charT, traits>&
    operator<<(basic_ostream<charT, traits>& os, const path& p);
`

[1](#fs.path.io-1)

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

*Effects*: Equivalent to os << quoted(p.string<charT, traits>())[.](#fs.path.io-1.sentence-1)

[*Note [1](#fs.path.io-note-1)*:

The quoted function is described in [[quoted.manip]](quoted.manip "31.7.9 Quoted manipulators")[.](#fs.path.io-1.sentence-2)

â *end note*]

[2](#fs.path.io-2)

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

*Returns*: os[.](#fs.path.io-2.sentence-1)

[ð](#lib:operator%3e%3e,path)

`template<class charT, class traits>
  friend basic_istream<charT, traits>&
    operator>>(basic_istream<charT, traits>& is, path& p);
`

[3](#fs.path.io-3)

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

*Effects*: Equivalent to:basic_string<charT, traits> tmp;
is >> quoted(tmp);
p = tmp;

[4](#fs.path.io-4)

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

*Returns*: is[.](#fs.path.io-4.sentence-1)

#### [31.12.6.8](#fs.path.nonmember) Non-member functions [[fs.path.nonmember]](fs.path.nonmember)

[ð](#lib:swap,path_)

`void swap(path& lhs, path& rhs) noexcept;
`

[1](#fs.path.nonmember-1)

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

*Effects*: Equivalent to lhs.swap(rhs)[.](#fs.path.nonmember-1.sentence-1)

[ð](#lib:hash_value,path)

`size_t hash_value(const path& p) noexcept;
`

[2](#fs.path.nonmember-2)

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

*Returns*: A hash value for the path p[.](#fs.path.nonmember-2.sentence-1)

If
 for two paths, p1 == p2 then hash_value(p1) == hash_value(p2)[.](#fs.path.nonmember-2.sentence-2)

[ð](#lib:operator==,path)

`friend bool operator==(const path& lhs, const path& rhs) noexcept;
`

[3](#fs.path.nonmember-3)

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

*Returns*: lhs.compare(rhs) == 0[.](#fs.path.nonmember-3.sentence-1)

[4](#fs.path.nonmember-4)

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

[*Note [1](#fs.path.nonmember-note-1)*:

Path equality and path equivalence have different semantics[.](#fs.path.nonmember-4.sentence-1)

- [(4.1)](#fs.path.nonmember-4.1)

  Equality is determined by the path non-member operator==,
which considers the two paths' lexical representations only[.](#fs.path.nonmember-4.1.sentence-1)
  [*Example [1](#fs.path.nonmember-example-1)*:
  path("foo") == "bar" is never true[.](#fs.path.nonmember-4.1.sentence-2)
 â *end example*]

- [(4.2)](#fs.path.nonmember-4.2)

  Equivalence is determined by the equivalent() non-member function, which
determines if two paths resolve ([[fs.class.path]](#fs.class.path "31.12.6 Class path")) to the same file system entity[.](#fs.path.nonmember-4.2.sentence-1)
  [*Example [2](#fs.path.nonmember-example-2)*:
  equivalent("foo", "bar") will be true when both paths resolve to the same file[.](#fs.path.nonmember-4.2.sentence-2)
 â *end example*]

â *end note*]

[ð](#lib:operator%3c=%3e,path)

`friend strong_ordering operator<=>(const path& lhs, const path& rhs) noexcept;
`

[5](#fs.path.nonmember-5)

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

*Returns*: lhs.compare(rhs) <=> 0[.](#fs.path.nonmember-5.sentence-1)

[ð](#lib:operator/,path)

`friend path operator/(const path& lhs, const path& rhs);
`

[6](#fs.path.nonmember-6)

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

*Effects*: Equivalent to: return path(lhs) /= rhs;

#### [31.12.6.9](#fs.path.fmtr) Formatting support [[fs.path.fmtr]](fs.path.fmtr)

#### [31.12.6.9.1](#fs.path.fmtr.general) Formatting support overview [[fs.path.fmtr.general]](fs.path.fmtr.general)

[ð](#lib:formatter)

namespace std {template<class charT> struct formatter<filesystem::path, charT> {constexpr void set_debug_format(); constexpr typename basic_format_parse_context<charT>::iterator
 parse(basic_format_parse_context<charT>& ctx); template<class FormatContext>typename FormatContext::iterator
 format(const filesystem::path& path, FormatContext& ctx) const; };}

#### [31.12.6.9.2](#fs.path.fmtr.funcs) Formatting support functions [[fs.path.fmtr.funcs]](fs.path.fmtr.funcs)

[1](#fs.path.fmtr.funcs-1)

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

Formatting of paths uses formatting specifiers of the form

[path-format-spec:](#nt:path-format-spec "31.12.6.9.2 Formatting support functions [fs.path.fmtr.funcs]")  
fill-and-alignopt widthopt ?opt gopt

where the productions *fill-and-align* and *width* are described in [[format.string]](format.string "28.5.2 Format string")[.](#fs.path.fmtr.funcs-1.sentence-1)

If the ? option is used then
the path is formatted as an escaped string ([[format.string.escaped]](format.string.escaped "28.5.6.5 Formatting escaped characters and strings"))[.](#fs.path.fmtr.funcs-1.sentence-2)

[ð](#lib:formatter,set_debug_format)

`constexpr void set_debug_format();
`

[2](#fs.path.fmtr.funcs-2)

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

*Effects*: Modifies the state of the formatter to be as if
the *path-format-spec* parsed by the last call to parse contained the ? option[.](#fs.path.fmtr.funcs-2.sentence-1)

[ð](#lib:formatter,basic_format_parse_context)

`constexpr typename basic_format_parse_context<charT>::iterator
  parse(basic_format_parse_context<charT>& ctx);
`

[3](#fs.path.fmtr.funcs-3)

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

*Effects*: Parses the format specifier as a *path-format-spec* and
stores the parsed specifiers in *this[.](#fs.path.fmtr.funcs-3.sentence-1)

[4](#fs.path.fmtr.funcs-4)

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

*Returns*: An iterator past the end of the *path-format-spec*[.](#fs.path.fmtr.funcs-4.sentence-1)

[ð](#lib:formatter,format)

`template<class FormatContext>
  typename FormatContext::iterator
    format(const filesystem::path& p, FormatContext& ctx) const;
`

[5](#fs.path.fmtr.funcs-5)

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

*Effects*: Let s be p.generic_string<filesystem​::​path​::​value_type>() if the g option is used,
otherwise p.native()[.](#fs.path.fmtr.funcs-5.sentence-1)

Writes s into ctx.out(),
adjusted according to the *path-format-spec*[.](#fs.path.fmtr.funcs-5.sentence-2)

If charT is char,path​::​value_type is wchar_t, and
the literal encoding is UTF-8,
then the escaped path is transcoded from the native encoding for
wide character strings to UTF-8 with
maximal subparts of ill-formed subsequences
substituted with U+fffd replacement character per the Unicode Standard, Chapter 3.9 U+fffd Substitution in Conversion[.](#fs.path.fmtr.funcs-5.sentence-3)

If charT and path​::​value_type are the same
then no transcoding is performed[.](#fs.path.fmtr.funcs-5.sentence-4)

Otherwise, transcoding isimplementation-defined[.](#fs.path.fmtr.funcs-5.sentence-5)

[6](#fs.path.fmtr.funcs-6)

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

*Returns*: An iterator past the end of the output range[.](#fs.path.fmtr.funcs-6.sentence-1)

#### [31.12.6.10](#fs.path.hash) Hash support [[fs.path.hash]](fs.path.hash)

[ð](#fs.path.hash-itemdecl:1)

`template<> struct hash<filesystem::path>;
`

[1](#fs.path.hash-1)

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

For an object p of type filesystem​::​path,hash<filesystem​::​path>()(p) evaluates to the same result asfilesystem​::​hash_value(p)[.](#fs.path.hash-1.sentence-1)

### [31.12.7](#fs.class.filesystem.error) Class filesystem_error [[fs.class.filesystem.error]](fs.class.filesystem.error)

#### [31.12.7.1](#fs.class.filesystem.error.general) General [[fs.class.filesystem.error.general]](fs.class.filesystem.error.general)

[ð](#lib:filesystem_error)

namespace std::filesystem {class filesystem_error : public system_error {public: filesystem_error(const string& what_arg, error_code ec);
 filesystem_error(const string& what_arg, const path& p1, error_code ec);
 filesystem_error(const string& what_arg, const path& p1, const path& p2, error_code ec); const path& path1() const noexcept; const path& path2() const noexcept; const char* what() const noexcept override; };}

[1](#fs.class.filesystem.error.general-1)

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

The class filesystem_error defines the type of
objects thrown as exceptions to report file system errors from functions described in
subclause [filesystems][.](#fs.class.filesystem.error.general-1.sentence-1)

#### [31.12.7.2](#fs.filesystem.error.members) Members [[fs.filesystem.error.members]](fs.filesystem.error.members)

[1](#fs.filesystem.error.members-1)

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

Constructors are provided that store zero, one, or two paths associated with
an error[.](#fs.filesystem.error.members-1.sentence-1)

[ð](#lib:filesystem_error,constructor)

`filesystem_error(const string& what_arg, error_code ec);
`

[2](#fs.filesystem.error.members-2)

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

*Postconditions*: 

- [(2.1)](#fs.filesystem.error.members-2.1)

code() == ec is true,

- [(2.2)](#fs.filesystem.error.members-2.2)

path1().empty() is true,

- [(2.3)](#fs.filesystem.error.members-2.3)

path2().empty() is true, and

- [(2.4)](#fs.filesystem.error.members-2.4)

string_view(what()).find(what_arg.c_str()) != string_view​::​npos is true[.](#fs.filesystem.error.members-2.sentence-1)

[ð](#lib:filesystem_error,constructor_)

`filesystem_error(const string& what_arg, const path& p1, error_code ec);
`

[3](#fs.filesystem.error.members-3)

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

*Postconditions*: 

- [(3.1)](#fs.filesystem.error.members-3.1)

code() == ec is true,

- [(3.2)](#fs.filesystem.error.members-3.2)

path1() returns a reference to the stored copy of p1,

- [(3.3)](#fs.filesystem.error.members-3.3)

path2().empty() is true, and

- [(3.4)](#fs.filesystem.error.members-3.4)

string_view(what()).find(what_arg.c_str()) != string_view​::​npos is true[.](#fs.filesystem.error.members-3.sentence-1)

[ð](#lib:filesystem_error,constructor__)

`filesystem_error(const string& what_arg, const path& p1, const path& p2, error_code ec);
`

[4](#fs.filesystem.error.members-4)

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

*Postconditions*: 

- [(4.1)](#fs.filesystem.error.members-4.1)

code() == ec,

- [(4.2)](#fs.filesystem.error.members-4.2)

path1() returns a reference to the stored copy of p1,

- [(4.3)](#fs.filesystem.error.members-4.3)

path2() returns a reference to the stored copy of p2, and

- [(4.4)](#fs.filesystem.error.members-4.4)

string_view(what()).find(what_arg.c_str()) != string_view​::​npos[.](#fs.filesystem.error.members-4.sentence-1)

[ð](#lib:path1,filesystem_error)

`const path& path1() const noexcept;
`

[5](#fs.filesystem.error.members-5)

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

*Returns*: A reference to the copy of p1 stored by the
 constructor, or, if none, an empty path[.](#fs.filesystem.error.members-5.sentence-1)

[ð](#lib:path2,filesystem_error)

`const path& path2() const noexcept;
`

[6](#fs.filesystem.error.members-6)

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

*Returns*: A reference to the copy of p2 stored by the
 constructor, or, if none, an empty path[.](#fs.filesystem.error.members-6.sentence-1)

[ð](#lib:what,filesystem_error)

`const char* what() const noexcept override;
`

[7](#fs.filesystem.error.members-7)

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

*Returns*: An ntbs that incorporates
 the what_arg argument supplied to the constructor[.](#fs.filesystem.error.members-7.sentence-1)

The exact format is unspecified[.](#fs.filesystem.error.members-7.sentence-2)

Implementations should include
 the system_error​::​what() string and
 the pathnames of path1 and path2 in the native format in the returned string[.](#fs.filesystem.error.members-7.sentence-3)

### [31.12.8](#fs.enum) Enumerations [[fs.enum]](fs.enum)

#### [31.12.8.1](#fs.enum.path.format) Enum path​::​format [[fs.enum.path.format]](fs.enum.path.format)

[1](#fs.enum.path.format-1)

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

This enum specifies constants used to identify the format of the character
sequence, with the meanings listed in Table [148](#tab:fs.enum.path.format "Table 148: Enum path​::​format")[.](#fs.enum.path.format-1.sentence-1)

Table [148](#tab:fs.enum.path.format) — Enum path​::​format [[tab:fs.enum.path.format]](./tab:fs.enum.path.format)  

| [ð](#tab:fs.enum.path.format-row-1)<br>**Name** | **Meaning** |
| --- | --- |
| [ð](#tab:fs.enum.path.format-row-2)<br>native_format | The native pathname format[.](#tab:fs.enum.path.format-row-2-column-2-sentence-1) |
| [ð](#tab:fs.enum.path.format-row-3)<br>generic_format | The generic pathname format[.](#tab:fs.enum.path.format-row-3-column-2-sentence-1) |
| [ð](#tab:fs.enum.path.format-row-4)<br>auto_format | The interpretation of the format of the character sequence is  implementation-defined[.](#tab:fs.enum.path.format-row-4-column-2-sentence-1)<br>The implementation may inspect the content of the character sequence to  determine the format[.](#tab:fs.enum.path.format-row-4-column-2-sentence-2)<br>*Recommended practice*: For POSIX-based systems, native and generic formats are equivalent  and the character sequence should always be interpreted in the same way[.](#tab:fs.enum.path.format-row-4-column-2-sentence-3) |

#### [31.12.8.2](#fs.enum.file.type) Enum class file_type [[fs.enum.file.type]](fs.enum.file.type)

[1](#fs.enum.file.type-1)

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

This enum class specifies constants used to identify file types,
with the meanings listed in Table [149](#tab:fs.enum.file.type "Table 149: Enum class file_­type")[.](#fs.enum.file.type-1.sentence-1)

The values of the constants are distinct[.](#fs.enum.file.type-1.sentence-2)

Table [149](#tab:fs.enum.file.type) — Enum class file_type [[tab:fs.enum.file.type]](./tab:fs.enum.file.type)  

| [ð](#tab:fs.enum.file.type-row-1)<br>**Constant** | **Meaning** |
| --- | --- |
| [ð](#tab:fs.enum.file.type-row-2)<br>[none](#lib:file_type,none "31.12.8.2 Enum class file_­type [fs.enum.file.type]") | The type of the file has not been determined or an error occurred while  trying to determine the type[.](#tab:fs.enum.file.type-row-2-column-2-sentence-1) |
| [ð](#tab:fs.enum.file.type-row-3)<br>[not_found](#lib:file_type,not_found "31.12.8.2 Enum class file_­type [fs.enum.file.type]") | Pseudo-type indicating the file was not found[.](#tab:fs.enum.file.type-row-3-column-2-sentence-1)<br>[*Note [1](#tab:fs.enum.file.type-row-3-column-2-note-1)*:<br>The file not being found is not considered an error while determining the type of a file[.](#tab:fs.enum.file.type-row-3-column-2-sentence-2) â *end note*] |
| [ð](#tab:fs.enum.file.type-row-4)<br>[regular](#lib:file_type,regular "31.12.8.2 Enum class file_­type [fs.enum.file.type]") | Regular file |
| [ð](#tab:fs.enum.file.type-row-5)<br>[directory](#lib:file_type,directory "31.12.8.2 Enum class file_­type [fs.enum.file.type]") | Directory file |
| [ð](#tab:fs.enum.file.type-row-6)<br>[symlink](#lib:file_type,symlink "31.12.8.2 Enum class file_­type [fs.enum.file.type]") | Symbolic link file |
| [ð](#tab:fs.enum.file.type-row-7)<br>[block](#lib:file_type,block "31.12.8.2 Enum class file_­type [fs.enum.file.type]") | Block special file |
| [ð](#tab:fs.enum.file.type-row-8)<br>[character](#lib:file_type,character "31.12.8.2 Enum class file_­type [fs.enum.file.type]") | Character special file |
| [ð](#tab:fs.enum.file.type-row-9)<br>[fifo](#lib:file_type,fifo "31.12.8.2 Enum class file_­type [fs.enum.file.type]") | FIFO or pipe file |
| [ð](#tab:fs.enum.file.type-row-10)<br>[socket](#lib:file_type,socket "31.12.8.2 Enum class file_­type [fs.enum.file.type]") | Socket file |
| [ð](#tab:fs.enum.file.type-row-11)<br>*implementation-defined* | Implementations that support file systems having file types in addition to the above file_type types shall supply implementation-defined file_type constants to separately identify each of those additional file types |
| [ð](#tab:fs.enum.file.type-row-12)<br>[unknown](#lib:file_type,unknown "31.12.8.2 Enum class file_­type [fs.enum.file.type]") | The file exists but the type cannot be determined |

#### [31.12.8.3](#fs.enum.copy.opts) Enum class copy_options [[fs.enum.copy.opts]](fs.enum.copy.opts)

[1](#fs.enum.copy.opts-1)

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

The enum class type copy_options is a bitmask type ([[bitmask.types]](bitmask.types "16.3.3.3.3 Bitmask types")) that specifies bitmask constants used to control the semantics of
copy operations[.](#fs.enum.copy.opts-1.sentence-1)

The constants are specified in option groups with the meanings listed in Table [150](#tab:fs.enum.copy.opts "Table 150: Enum class copy_­options")[.](#fs.enum.copy.opts-1.sentence-2)

The constant none represents the empty bitmask, and
is shown in each option group for purposes of exposition;
implementations shall provide only a single definition[.](#fs.enum.copy.opts-1.sentence-3)

Every other constant in the table represents a distinct bitmask element[.](#fs.enum.copy.opts-1.sentence-4)

Table [150](#tab:fs.enum.copy.opts) — Enum class copy_options [[tab:fs.enum.copy.opts]](./tab:fs.enum.copy.opts)  

| [ð](#tab:fs.enum.copy.opts-row-1)<br>**Option group controlling copy_file function effects for existing target files** | |
| --- | --- |
| [ð](#tab:fs.enum.copy.opts-row-2)<br>**Constant** | **Meaning** |
| [ð](#tab:fs.enum.copy.opts-row-3)<br>[none](#lib:copy_options,none "31.12.8.3 Enum class copy_­options [fs.enum.copy.opts]") | (Default) Error; file already exists[.](#tab:fs.enum.copy.opts-row-3-column-2-sentence-1) |
| [ð](#tab:fs.enum.copy.opts-row-4)<br>[skip_existing](#lib:copy_options,skip_existing "31.12.8.3 Enum class copy_­options [fs.enum.copy.opts]") | Do not overwrite existing file, do not report an error[.](#tab:fs.enum.copy.opts-row-4-column-2-sentence-1) |
| [ð](#tab:fs.enum.copy.opts-row-5)<br>[overwrite_existing](#lib:copy_options,overwrite_existing "31.12.8.3 Enum class copy_­options [fs.enum.copy.opts]") | Overwrite the existing file[.](#tab:fs.enum.copy.opts-row-5-column-2-sentence-1) |
| [ð](#tab:fs.enum.copy.opts-row-6)<br>[update_existing](#lib:copy_options,update_existing "31.12.8.3 Enum class copy_­options [fs.enum.copy.opts]") | Overwrite the existing file if it is older than the replacement file[.](#tab:fs.enum.copy.opts-row-6-column-2-sentence-1) |
| [ð](#tab:fs.enum.copy.opts-row-7)<br>**Option group controlling copy function effects for subdirectories** | |
| [ð](#tab:fs.enum.copy.opts-row-8)<br>**Constant** | **Meaning** |
| [ð](#tab:fs.enum.copy.opts-row-9)<br>[none](#lib:copy_options,none "31.12.8.3 Enum class copy_­options [fs.enum.copy.opts]") | (Default) Do not copy subdirectories[.](#tab:fs.enum.copy.opts-row-9-column-2-sentence-1) |
| [ð](#tab:fs.enum.copy.opts-row-10)<br>[recursive](#lib:copy_options,recursive "31.12.8.3 Enum class copy_­options [fs.enum.copy.opts]") | Recursively copy subdirectories and their contents[.](#tab:fs.enum.copy.opts-row-10-column-2-sentence-1) |
| [ð](#tab:fs.enum.copy.opts-row-11)<br>**Option group controlling copy function effects for symbolic links** | |
| [ð](#tab:fs.enum.copy.opts-row-12)<br>**Constant** | **Meaning** |
| [ð](#tab:fs.enum.copy.opts-row-13)<br>[none](#lib:copy_options,none "31.12.8.3 Enum class copy_­options [fs.enum.copy.opts]") | (Default) Follow symbolic links[.](#tab:fs.enum.copy.opts-row-13-column-2-sentence-1) |
| [ð](#tab:fs.enum.copy.opts-row-14)<br>[copy_symlinks](#lib:copy_options,copy_symlinks "31.12.8.3 Enum class copy_­options [fs.enum.copy.opts]") | Copy symbolic links as symbolic links rather than copying the files that  they point to[.](#tab:fs.enum.copy.opts-row-14-column-2-sentence-1) |
| [ð](#tab:fs.enum.copy.opts-row-15)<br>[skip_symlinks](#lib:copy_options,skip_symlinks "31.12.8.3 Enum class copy_­options [fs.enum.copy.opts]") | Ignore symbolic links[.](#tab:fs.enum.copy.opts-row-15-column-2-sentence-1) |
| [ð](#tab:fs.enum.copy.opts-row-16)<br>**Option group controlling copy function effects for choosing the form of copying** | |
| [ð](#tab:fs.enum.copy.opts-row-17)<br>**Constant** | **Meaning** |
| [ð](#tab:fs.enum.copy.opts-row-18)<br>[none](#lib:copy_options,none "31.12.8.3 Enum class copy_­options [fs.enum.copy.opts]") | (Default) Copy content[.](#tab:fs.enum.copy.opts-row-18-column-2-sentence-1) |
| [ð](#tab:fs.enum.copy.opts-row-19)<br>[directories_only](#lib:copy_options,directories_only "31.12.8.3 Enum class copy_­options [fs.enum.copy.opts]") | Copy directory structure only, do not copy non-directory files[.](#tab:fs.enum.copy.opts-row-19-column-2-sentence-1) |
| [ð](#tab:fs.enum.copy.opts-row-20)<br>[create_symlinks](#lib:copy_options,create_symlinks "31.12.8.3 Enum class copy_­options [fs.enum.copy.opts]") | Make symbolic links instead of copies of files[.](#tab:fs.enum.copy.opts-row-20-column-2-sentence-1)<br>The source path shall be  an absolute path unless the destination path is in the current directory[.](#tab:fs.enum.copy.opts-row-20-column-2-sentence-2) |
| [ð](#tab:fs.enum.copy.opts-row-21)<br>[create_hard_links](#lib:copy_options,create_hard_links "31.12.8.3 Enum class copy_­options [fs.enum.copy.opts]") | Make hard links instead of copies of files[.](#tab:fs.enum.copy.opts-row-21-column-2-sentence-1) |

#### [31.12.8.4](#fs.enum.perms) Enum class perms [[fs.enum.perms]](fs.enum.perms)

[1](#fs.enum.perms-1)

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

The enum class type perms is a bitmask type ([[bitmask.types]](bitmask.types "16.3.3.3.3 Bitmask types")) that specifies bitmask constants used to identify file
permissions, with the meanings listed in Table [151](#tab:fs.enum.perms "Table 151: Enum class perms")[.](#fs.enum.perms-1.sentence-1)

Table [151](#tab:fs.enum.perms) — Enum class perms [[tab:fs.enum.perms]](./tab:fs.enum.perms)  

| [ð](#tab:fs.enum.perms-row-1)<br>**Name** | **Value** | **POSIX** | **Definition or notes** |
| --- | --- | --- | --- |
| [ð](#tab:fs.enum.perms-row-2) | **(octal)** | **macro** |  |
| [ð](#tab:fs.enum.perms-row-3)<br>[none](#lib:perms,none "31.12.8.4 Enum class perms [fs.enum.perms]") | 0 |  | There are no permissions set for the file[.](#tab:fs.enum.perms-row-3-column-4-sentence-1) |
| [ð](#tab:fs.enum.perms-row-4)<br>[owner_read](#lib:perms,owner_read "31.12.8.4 Enum class perms [fs.enum.perms]") | 0400 | S_IRUSR | Read permission, owner |
| [ð](#tab:fs.enum.perms-row-5)<br>[owner_write](#lib:perms,owner_write "31.12.8.4 Enum class perms [fs.enum.perms]") | 0200 | S_IWUSR | Write permission, owner |
| [ð](#tab:fs.enum.perms-row-6)<br>[owner_exec](#lib:perms,owner_exec "31.12.8.4 Enum class perms [fs.enum.perms]") | 0100 | S_IXUSR | Execute/search permission, owner |
| [ð](#tab:fs.enum.perms-row-7)<br>[owner_all](#lib:perms,owner_all "31.12.8.4 Enum class perms [fs.enum.perms]") | 0700 | S_IRWXU | Read, write, execute/search by owner;   owner_read | owner_write | owner_exec |
| [ð](#tab:fs.enum.perms-row-8)<br>[group_read](#lib:perms,group_read "31.12.8.4 Enum class perms [fs.enum.perms]") | 040 | S_IRGRP | Read permission, group |
| [ð](#tab:fs.enum.perms-row-9)<br>[group_write](#lib:perms,group_write "31.12.8.4 Enum class perms [fs.enum.perms]") | 020 | S_IWGRP | Write permission, group |
| [ð](#tab:fs.enum.perms-row-10)<br>[group_exec](#lib:perms,group_exec "31.12.8.4 Enum class perms [fs.enum.perms]") | 010 | S_IXGRP | Execute/search permission, group |
| [ð](#tab:fs.enum.perms-row-11)<br>[group_all](#lib:perms,group_all "31.12.8.4 Enum class perms [fs.enum.perms]") | 070 | S_IRWXG | Read, write, execute/search by group;   group_read | group_write | group_exec |
| [ð](#tab:fs.enum.perms-row-12)<br>[others_read](#lib:perms,others_read "31.12.8.4 Enum class perms [fs.enum.perms]") | 04 | S_IROTH | Read permission, others |
| [ð](#tab:fs.enum.perms-row-13)<br>[others_write](#lib:perms,others_write "31.12.8.4 Enum class perms [fs.enum.perms]") | 02 | S_IWOTH | Write permission, others |
| [ð](#tab:fs.enum.perms-row-14)<br>[others_exec](#lib:perms,others_exec "31.12.8.4 Enum class perms [fs.enum.perms]") | 01 | S_IXOTH | Execute/search permission, others |
| [ð](#tab:fs.enum.perms-row-15)<br>[others_all](#lib:perms,others_all "31.12.8.4 Enum class perms [fs.enum.perms]") | 07 | S_IRWXO | Read, write, execute/search by others;   others_read | others_write | others_exec |
| [ð](#tab:fs.enum.perms-row-16)<br>[all](#lib:perms,all "31.12.8.4 Enum class perms [fs.enum.perms]") | 0777 |  | owner_all | group_all | others_all |
| [ð](#tab:fs.enum.perms-row-17)<br>[set_uid](#lib:perms,set_uid "31.12.8.4 Enum class perms [fs.enum.perms]") | 04000 | S_ISUID | Set-user-ID on execution |
| [ð](#tab:fs.enum.perms-row-18)<br>[set_gid](#lib:perms,set_gid "31.12.8.4 Enum class perms [fs.enum.perms]") | 02000 | S_ISGID | Set-group-ID on execution |
| [ð](#tab:fs.enum.perms-row-19)<br>[sticky_bit](#lib:perms,sticky_bit "31.12.8.4 Enum class perms [fs.enum.perms]") | 01000 | S_ISVTX | Operating system dependent[.](#tab:fs.enum.perms-row-19-column-4-sentence-1) |
| [ð](#tab:fs.enum.perms-row-20)<br>[mask](#lib:perms,mask "31.12.8.4 Enum class perms [fs.enum.perms]") | 07777 |  | all | set_uid | set_gid | sticky_bit |
| [ð](#tab:fs.enum.perms-row-21)<br>[unknown](#lib:perms,unknown "31.12.8.4 Enum class perms [fs.enum.perms]") | 0xFFFF |  | The permissions are not known, such as when a file_status object  is created without specifying the permissions |

#### [31.12.8.5](#fs.enum.perm.opts) Enum class perm_options [[fs.enum.perm.opts]](fs.enum.perm.opts)

[1](#fs.enum.perm.opts-1)

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

The enum class type perm_options is a bitmask type ([[bitmask.types]](bitmask.types "16.3.3.3.3 Bitmask types")) that specifies bitmask constants used to
control the semantics of permissions operations,
with the meanings listed in Table [152](#tab:fs.enum.perm.opts "Table 152: Enum class perm_­options")[.](#fs.enum.perm.opts-1.sentence-1)

The bitmask constants are bitmask elements[.](#fs.enum.perm.opts-1.sentence-2)

In Table [152](#tab:fs.enum.perm.opts "Table 152: Enum class perm_­options") perm denotes a value of type perms passed to permissions[.](#fs.enum.perm.opts-1.sentence-3)

Table [152](#tab:fs.enum.perm.opts) — Enum class perm_options [[tab:fs.enum.perm.opts]](./tab:fs.enum.perm.opts)  

| [ð](#tab:fs.enum.perm.opts-row-1)<br>**Name** | **Meaning** |
| --- | --- |
| [ð](#tab:fs.enum.perm.opts-row-2)<br>[replace](#lib:perm_options,replace "31.12.8.5 Enum class perm_­options [fs.enum.perm.opts]") | permissions shall replace the file's permission bits with perm |
| [ð](#tab:fs.enum.perm.opts-row-3)<br>[add](#lib:perm_options,add "31.12.8.5 Enum class perm_­options [fs.enum.perm.opts]") | permissions shall replace the file's permission bits with  the bitwise or of perm and the file's current permission bits[.](#tab:fs.enum.perm.opts-row-3-column-2-sentence-1) |
| [ð](#tab:fs.enum.perm.opts-row-4)<br>[remove](#lib:perm_options,remove "31.12.8.5 Enum class perm_­options [fs.enum.perm.opts]") | permissions shall replace the file's permission bits with  the bitwise and of the complement of perm and the file's current permission bits[.](#tab:fs.enum.perm.opts-row-4-column-2-sentence-1) |
| [ð](#tab:fs.enum.perm.opts-row-5)<br>[nofollow](#lib:perm_options,nofollow "31.12.8.5 Enum class perm_­options [fs.enum.perm.opts]") | permissions shall change the permissions of a symbolic link itself  rather than the permissions of the file the link resolves to[.](#tab:fs.enum.perm.opts-row-5-column-2-sentence-1) |

#### [31.12.8.6](#fs.enum.dir.opts) Enum class directory_options [[fs.enum.dir.opts]](fs.enum.dir.opts)

[1](#fs.enum.dir.opts-1)

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

The enum class type directory_options is a bitmask
 type ([[bitmask.types]](bitmask.types "16.3.3.3.3 Bitmask types")) that specifies bitmask constants used to identify
 directory traversal options, with the meanings listed in Table [153](#tab:fs.enum.dir.opts "Table 153: Enum class directory_­options")[.](#fs.enum.dir.opts-1.sentence-1)

The constant none represents the empty bitmask;
 every other constant in the table represents a distinct bitmask element[.](#fs.enum.dir.opts-1.sentence-2)

Table [153](#tab:fs.enum.dir.opts) — Enum class directory_options [[tab:fs.enum.dir.opts]](./tab:fs.enum.dir.opts)  

| [ð](#tab:fs.enum.dir.opts-row-1)<br>**Name** | **Meaning** |
| --- | --- |
| [ð](#tab:fs.enum.dir.opts-row-2)<br>[none](#lib:directory_options,none "31.12.8.6 Enum class directory_­options [fs.enum.dir.opts]") | (Default) Skip directory symlinks, permission denied is an error[.](#tab:fs.enum.dir.opts-row-2-column-2-sentence-1) |
| [ð](#tab:fs.enum.dir.opts-row-3)<br>[follow_directory_symlink](#lib:directory_options,follow_directory_symlink "31.12.8.6 Enum class directory_­options [fs.enum.dir.opts]") | Follow rather than skip directory symlinks[.](#tab:fs.enum.dir.opts-row-3-column-2-sentence-1) |
| [ð](#tab:fs.enum.dir.opts-row-4)<br>[skip_permission_denied](#lib:directory_options,skip_permission_denied "31.12.8.6 Enum class directory_­options [fs.enum.dir.opts]") | Skip directories that would otherwise result in permission denied[.](#tab:fs.enum.dir.opts-row-4-column-2-sentence-1) |

### [31.12.9](#fs.class.file.status) Class file_status [[fs.class.file.status]](fs.class.file.status)

#### [31.12.9.1](#fs.class.file.status.general) General [[fs.class.file.status.general]](fs.class.file.status.general)

[ð](#lib:file_status)

namespace std::filesystem {class file_status {public:// [[fs.file.status.cons]](#fs.file.status.cons "31.12.9.2 Constructors"), constructors and destructor file_status() noexcept : file_status(file_type::none) {}explicit file_status(file_type ft,
 perms prms = perms::unknown) noexcept;
 file_status(const file_status&) noexcept = default;
 file_status(file_status&&) noexcept = default; ~file_status(); // assignments file_status& operator=(const file_status&) noexcept = default;
 file_status& operator=(file_status&&) noexcept = default; // [[fs.file.status.mods]](#fs.file.status.mods "31.12.9.4 Modifiers"), modifiersvoid type(file_type ft) noexcept; void permissions(perms prms) noexcept; // [[fs.file.status.obs]](#fs.file.status.obs "31.12.9.3 Observers"), observers file_type type() const noexcept;
 perms permissions() const noexcept; friend bool operator==(const file_status& lhs, const file_status& rhs) noexcept{ return lhs.type() == rhs.type() && lhs.permissions() == rhs.permissions(); }};}

[1](#fs.class.file.status.general-1)

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

An object of type file_status stores information about the type
and permissions of a file[.](#fs.class.file.status.general-1.sentence-1)

#### [31.12.9.2](#fs.file.status.cons) Constructors [[fs.file.status.cons]](fs.file.status.cons)

[ð](#lib:file_status,constructor)

`explicit file_status(file_type ft, perms prms = perms::unknown) noexcept;
`

[1](#fs.file.status.cons-1)

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

*Postconditions*: type() == ft and permissions() == prms[.](#fs.file.status.cons-1.sentence-1)

#### [31.12.9.3](#fs.file.status.obs) Observers [[fs.file.status.obs]](fs.file.status.obs)

[ð](#lib:type,file_status)

`file_type type() const noexcept;
`

[1](#fs.file.status.obs-1)

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

*Returns*: The value of type() specified by the postconditions of the most recent call to a constructor, operator=, or type(file_type) function[.](#fs.file.status.obs-1.sentence-1)

[ð](#lib:permissions,file_status)

`perms permissions() const noexcept;
`

[2](#fs.file.status.obs-2)

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

*Returns*: The value of permissions() specified by the postconditions of the most recent call to a constructor, operator=, or permissions(perms) function[.](#fs.file.status.obs-2.sentence-1)

#### [31.12.9.4](#fs.file.status.mods) Modifiers [[fs.file.status.mods]](fs.file.status.mods)

[ð](#lib:type,file_status_)

`void type(file_type ft) noexcept;
`

[1](#fs.file.status.mods-1)

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

*Postconditions*: type() == ft[.](#fs.file.status.mods-1.sentence-1)

[ð](#lib:permissions,file_status_)

`void permissions(perms prms) noexcept;
`

[2](#fs.file.status.mods-2)

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

*Postconditions*: permissions() == prms[.](#fs.file.status.mods-2.sentence-1)

### [31.12.10](#fs.class.directory.entry) Class directory_entry [[fs.class.directory.entry]](fs.class.directory.entry)

#### [31.12.10.1](#fs.class.directory.entry.general) General [[fs.class.directory.entry.general]](fs.class.directory.entry.general)

[ð](#lib:directory_entry)

namespace std::filesystem {class directory_entry {public:// [[fs.dir.entry.cons]](#fs.dir.entry.cons "31.12.10.2 Constructors"), constructors and destructor directory_entry() noexcept = default;
 directory_entry(const directory_entry&) = default;
 directory_entry(directory_entry&&) noexcept = default; explicit directory_entry(const filesystem::path& p);
 directory_entry(const filesystem::path& p, error_code& ec); ~directory_entry(); // assignments directory_entry& operator=(const directory_entry&) = default;
 directory_entry& operator=(directory_entry&&) noexcept = default; // [[fs.dir.entry.mods]](#fs.dir.entry.mods "31.12.10.3 Modifiers"), modifiersvoid assign(const filesystem::path& p); void assign(const filesystem::path& p, error_code& ec); void replace_filename(const filesystem::path& p); void replace_filename(const filesystem::path& p, error_code& ec); void refresh(); void refresh(error_code& ec) noexcept; // [[fs.dir.entry.obs]](#fs.dir.entry.obs "31.12.10.4 Observers"), observersconst filesystem::path& path() const noexcept; operator const filesystem::path&() const noexcept; bool exists() const; bool exists(error_code& ec) const noexcept; bool is_block_file() const; bool is_block_file(error_code& ec) const noexcept; bool is_character_file() const; bool is_character_file(error_code& ec) const noexcept; bool is_directory() const; bool is_directory(error_code& ec) const noexcept; bool is_fifo() const; bool is_fifo(error_code& ec) const noexcept; bool is_other() const; bool is_other(error_code& ec) const noexcept; bool is_regular_file() const; bool is_regular_file(error_code& ec) const noexcept; bool is_socket() const; bool is_socket(error_code& ec) const noexcept; bool is_symlink() const; bool is_symlink(error_code& ec) const noexcept;
 uintmax_t file_size() const;
 uintmax_t file_size(error_code& ec) const noexcept;
 uintmax_t hard_link_count() const;
 uintmax_t hard_link_count(error_code& ec) const noexcept;
 file_time_type last_write_time() const;
 file_time_type last_write_time(error_code& ec) const noexcept;
 file_status status() const;
 file_status status(error_code& ec) const noexcept;
 file_status symlink_status() const;
 file_status symlink_status(error_code& ec) const noexcept; bool operator==(const directory_entry& rhs) const noexcept;
 strong_ordering operator<=>(const directory_entry& rhs) const noexcept; // [[fs.dir.entry.io]](#fs.dir.entry.io "31.12.10.5 Inserter"), insertertemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const directory_entry& d); private: filesystem::path *path-object*; // *exposition only*};}

[1](#fs.class.directory.entry.general-1)

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

A directory_entry object stores a path object
and may store additional objects for file attributes
such as hard link count, status, symlink status, file size, and last write time[.](#fs.class.directory.entry.general-1.sentence-1)

[2](#fs.class.directory.entry.general-2)

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

Implementations should store such additional file attributes
during directory iteration if their values are available
and storing the values would allow the implementation to eliminate file system accesses
by directory_entry observer functions ([[fs.op.funcs]](#fs.op.funcs "31.12.13 Filesystem operation functions"))[.](#fs.class.directory.entry.general-2.sentence-1)

Such stored file attribute values are said to be [*cached*](#def:file_attributes,cached "31.12.10.1 General [fs.class.directory.entry.general]")[.](#fs.class.directory.entry.general-2.sentence-2)

[3](#fs.class.directory.entry.general-3)

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

[*Note [1](#fs.class.directory.entry.general-note-1)*:

directory_iterator can cache
already available attribute values
directly into a directory_entry object
without the cost of a call to refresh()[.](#fs.class.directory.entry.general-3.sentence-1)

â *end note*]

[4](#fs.class.directory.entry.general-4)

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

[*Example [1](#fs.class.directory.entry.general-example-1)*: using namespace std::filesystem;

// use possibly cached last write time to minimize disk accessesfor (auto&& x : directory_iterator(".")){ std::cout << x.path() << " " << x.last_write_time() << std::endl;}// call refresh() to refresh a stale cachefor (auto&& x : directory_iterator(".")){ lengthy_function(x.path()); // cache becomes stale x.refresh();
 std::cout << x.path() << " " << x.last_write_time() << std::endl;}

On implementations that do not cache the last write time,
both loops will result in a potentially expensive call
to the std​::​filesystem​::​last_write_time function[.](#fs.class.directory.entry.general-4.sentence-1)

On implementations that do cache the last write time,
the first loop will use the cached value and so
will not result in a potentially expensive call
to the std​::​filesystem​::​last_write_time function[.](#fs.class.directory.entry.general-4.sentence-2)

The code is portable to any implementation,
regardless of whether or not it employs caching[.](#fs.class.directory.entry.general-4.sentence-3)

â *end example*]

#### [31.12.10.2](#fs.dir.entry.cons) Constructors [[fs.dir.entry.cons]](fs.dir.entry.cons)

[ð](#lib:directory_entry,constructor)

`explicit directory_entry(const filesystem::path& p);
directory_entry(const filesystem::path& p, error_code& ec);
`

[1](#fs.dir.entry.cons-1)

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

*Effects*: Calls refresh() or refresh(ec), respectively[.](#fs.dir.entry.cons-1.sentence-1)

[2](#fs.dir.entry.cons-2)

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

*Postconditions*: path() == p if no error occurs,
otherwise path() == filesystem​::​path()[.](#fs.dir.entry.cons-2.sentence-1)

[3](#fs.dir.entry.cons-3)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.dir.entry.cons-3.sentence-1)

#### [31.12.10.3](#fs.dir.entry.mods) Modifiers [[fs.dir.entry.mods]](fs.dir.entry.mods)

[ð](#lib:assign,directory_entry)

`void assign(const filesystem::path& p);
void assign(const filesystem::path& p, error_code& ec);
`

[1](#fs.dir.entry.mods-1)

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

*Effects*: Equivalent to *path-object* = p,
then refresh() or refresh(ec), respectively[.](#fs.dir.entry.mods-1.sentence-1)

If an error occurs, the values of any cached attributes are unspecified[.](#fs.dir.entry.mods-1.sentence-2)

[2](#fs.dir.entry.mods-2)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.dir.entry.mods-2.sentence-1)

[ð](#lib:replace_filename,directory_entry)

`void replace_filename(const filesystem::path& p);
void replace_filename(const filesystem::path& p, error_code& ec);
`

[3](#fs.dir.entry.mods-3)

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

*Effects*: Equivalent to *path-object*.replace_filename(p),
then refresh() or refresh(ec), respectively[.](#fs.dir.entry.mods-3.sentence-1)

If an error occurs, the values of any cached attributes are unspecified[.](#fs.dir.entry.mods-3.sentence-2)

[4](#fs.dir.entry.mods-4)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.dir.entry.mods-4.sentence-1)

[ð](#lib:refresh,directory_entry)

`void refresh();
void refresh(error_code& ec) noexcept;
`

[5](#fs.dir.entry.mods-5)

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

*Effects*: Stores the current values of any cached attributes of the file p resolves to[.](#fs.dir.entry.mods-5.sentence-1)

If an error occurs, an error is reported ([[fs.err.report]](#fs.err.report "31.12.5 Error reporting"))
and the values of any cached attributes are unspecified[.](#fs.dir.entry.mods-5.sentence-2)

[6](#fs.dir.entry.mods-6)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.dir.entry.mods-6.sentence-1)

[7](#fs.dir.entry.mods-7)

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

[*Note [1](#fs.dir.entry.mods-note-1)*:

Implementations of directory_iterator ([[fs.class.directory.iterator]](#fs.class.directory.iterator "31.12.11 Class directory_­iterator"))
are prohibited from directly or indirectly calling the refresh function
as described in [[fs.class.directory.iterator.general]](#fs.class.directory.iterator.general "31.12.11.1 General")[.](#fs.dir.entry.mods-7.sentence-1)

â *end note*]

#### [31.12.10.4](#fs.dir.entry.obs) Observers [[fs.dir.entry.obs]](fs.dir.entry.obs)

[1](#fs.dir.entry.obs-1)

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

Unqualified function names in the *Returns*: elements of thedirectory_entry observers described below refer to members of thestd​::​filesystem namespace[.](#fs.dir.entry.obs-1.sentence-1)

[ð](#lib:path,directory_entry)

`const filesystem::path& path() const noexcept;
operator const filesystem::path&() const noexcept;
`

[2](#fs.dir.entry.obs-2)

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

*Returns*: *path-object*[.](#fs.dir.entry.obs-2.sentence-1)

[ð](#lib:exists,directory_entry)

`bool exists() const;
bool exists(error_code& ec) const noexcept;
`

[3](#fs.dir.entry.obs-3)

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

*Returns*: exists(this->status()) or exists(this->status(ec)), respectively[.](#fs.dir.entry.obs-3.sentence-1)

[4](#fs.dir.entry.obs-4)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.dir.entry.obs-4.sentence-1)

[ð](#lib:is_block_file,directory_entry)

`bool is_block_file() const;
bool is_block_file(error_code& ec) const noexcept;
`

[5](#fs.dir.entry.obs-5)

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

*Returns*: is_block_file(this->status()) or is_block_file(this->status(ec)), respectively[.](#fs.dir.entry.obs-5.sentence-1)

[6](#fs.dir.entry.obs-6)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.dir.entry.obs-6.sentence-1)

[ð](#lib:is_character_file,directory_entry)

`bool is_character_file() const;
bool is_character_file(error_code& ec) const noexcept;
`

[7](#fs.dir.entry.obs-7)

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

*Returns*: is_character_file(this->status()) or is_character_file(this->status(ec)), respectively[.](#fs.dir.entry.obs-7.sentence-1)

[8](#fs.dir.entry.obs-8)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.dir.entry.obs-8.sentence-1)

[ð](#lib:is_directory,directory_entry)

`bool is_directory() const;
bool is_directory(error_code& ec) const noexcept;
`

[9](#fs.dir.entry.obs-9)

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

*Returns*: is_directory(this->status()) or is_directory(this->status(ec)), respectively[.](#fs.dir.entry.obs-9.sentence-1)

[10](#fs.dir.entry.obs-10)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.dir.entry.obs-10.sentence-1)

[ð](#lib:is_fifo,directory_entry)

`bool is_fifo() const;
bool is_fifo(error_code& ec) const noexcept;
`

[11](#fs.dir.entry.obs-11)

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

*Returns*: is_fifo(this->status()) or is_fifo(this->status(ec)), respectively[.](#fs.dir.entry.obs-11.sentence-1)

[12](#fs.dir.entry.obs-12)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.dir.entry.obs-12.sentence-1)

[ð](#lib:is_other,directory_entry)

`bool is_other() const;
bool is_other(error_code& ec) const noexcept;
`

[13](#fs.dir.entry.obs-13)

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

*Returns*: is_other(this->status()) or is_other(this->status(ec)), respectively[.](#fs.dir.entry.obs-13.sentence-1)

[14](#fs.dir.entry.obs-14)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.dir.entry.obs-14.sentence-1)

[ð](#lib:is_regular_file,directory_entry)

`bool is_regular_file() const;
bool is_regular_file(error_code& ec) const noexcept;
`

[15](#fs.dir.entry.obs-15)

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

*Returns*: is_regular_file(this->status()) or is_regular_file(this->status(ec)), respectively[.](#fs.dir.entry.obs-15.sentence-1)

[16](#fs.dir.entry.obs-16)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.dir.entry.obs-16.sentence-1)

[ð](#lib:is_socket,directory_entry)

`bool is_socket() const;
bool is_socket(error_code& ec) const noexcept;
`

[17](#fs.dir.entry.obs-17)

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

*Returns*: is_socket(this->status()) or is_socket(this->status(ec)), respectively[.](#fs.dir.entry.obs-17.sentence-1)

[18](#fs.dir.entry.obs-18)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.dir.entry.obs-18.sentence-1)

[ð](#lib:is_symlink,directory_entry)

`bool is_symlink() const;
bool is_symlink(error_code& ec) const noexcept;
`

[19](#fs.dir.entry.obs-19)

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

*Returns*: is_symlink(this->symlink_status()) or is_symlink(this->symlink_status(ec)), respectively[.](#fs.dir.entry.obs-19.sentence-1)

[20](#fs.dir.entry.obs-20)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.dir.entry.obs-20.sentence-1)

[ð](#lib:file_size,directory_entry)

`uintmax_t file_size() const;
uintmax_t file_size(error_code& ec) const noexcept;
`

[21](#fs.dir.entry.obs-21)

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

*Returns*: If cached, the file size attribute value[.](#fs.dir.entry.obs-21.sentence-1)

Otherwise, file_size(path()) or file_size(path(), ec), respectively[.](#fs.dir.entry.obs-21.sentence-2)

[22](#fs.dir.entry.obs-22)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.dir.entry.obs-22.sentence-1)

[ð](#lib:hard_link_count,directory_entry)

`uintmax_t hard_link_count() const;
uintmax_t hard_link_count(error_code& ec) const noexcept;
`

[23](#fs.dir.entry.obs-23)

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

*Returns*: If cached, the hard link count attribute value[.](#fs.dir.entry.obs-23.sentence-1)

Otherwise, hard_link_count(path()) or hard_link_count(path(), ec), respectively[.](#fs.dir.entry.obs-23.sentence-2)

[24](#fs.dir.entry.obs-24)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.dir.entry.obs-24.sentence-1)

[ð](#lib:last_write_time,directory_entry)

`file_time_type last_write_time() const;
file_time_type last_write_time(error_code& ec) const noexcept;
`

[25](#fs.dir.entry.obs-25)

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

*Returns*: If cached, the last write time attribute value[.](#fs.dir.entry.obs-25.sentence-1)

Otherwise, last_write_time(path()) or last_write_time(path(), ec), respectively[.](#fs.dir.entry.obs-25.sentence-2)

[26](#fs.dir.entry.obs-26)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.dir.entry.obs-26.sentence-1)

[ð](#lib:status,directory_entry)

`file_status status() const;
file_status status(error_code& ec) const noexcept;
`

[27](#fs.dir.entry.obs-27)

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

*Returns*: If cached, the status attribute value[.](#fs.dir.entry.obs-27.sentence-1)

Otherwise, status(path()) or status(path(), ec), respectively[.](#fs.dir.entry.obs-27.sentence-2)

[28](#fs.dir.entry.obs-28)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.dir.entry.obs-28.sentence-1)

[ð](#lib:symlink_status,directory_entry)

`file_status symlink_status() const;
file_status symlink_status(error_code& ec) const noexcept;
`

[29](#fs.dir.entry.obs-29)

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

*Returns*: If cached, the symlink status attribute value[.](#fs.dir.entry.obs-29.sentence-1)

Otherwise, symlink_status(path()) or symlink_status(path(), ec), respectively[.](#fs.dir.entry.obs-29.sentence-2)

[30](#fs.dir.entry.obs-30)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.dir.entry.obs-30.sentence-1)

[ð](#lib:operator==,directory_entry)

`bool operator==(const directory_entry& rhs) const noexcept;
`

[31](#fs.dir.entry.obs-31)

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

*Returns*: *path-object* == rhs.*path-object*[.](#fs.dir.entry.obs-31.sentence-1)

[ð](#lib:operator%3c=%3e,directory_entry)

`strong_ordering operator<=>(const directory_entry& rhs) const noexcept;
`

[32](#fs.dir.entry.obs-32)

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

*Returns*: *path-object* <=> rhs.*path-object*[.](#fs.dir.entry.obs-32.sentence-1)

#### [31.12.10.5](#fs.dir.entry.io) Inserter [[fs.dir.entry.io]](fs.dir.entry.io)

[ð](#lib:operator%3c%3c,directory_entry)

`template<class charT, class traits>
  friend basic_ostream<charT, traits>&
    operator<<(basic_ostream<charT, traits>& os, const directory_entry& d);
`

[1](#fs.dir.entry.io-1)

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

*Effects*: Equivalent to: return os << d.path();

### [31.12.11](#fs.class.directory.iterator) Class directory_iterator [[fs.class.directory.iterator]](fs.class.directory.iterator)

#### [31.12.11.1](#fs.class.directory.iterator.general) General [[fs.class.directory.iterator.general]](fs.class.directory.iterator.general)

[1](#fs.class.directory.iterator.general-1)

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

An object of type directory_iterator provides an iterator for a
sequence of directory_entry elements representing the
path and any cached attribute values ([[fs.class.directory.entry]](#fs.class.directory.entry "31.12.10 Class directory_­entry"))
for each file in a directory
or in an implementation-defined directory-like file type[.](#fs.class.directory.iterator.general-1.sentence-1)

[*Note [1](#fs.class.directory.iterator.general-note-1)*:

For iteration into subdirectories, see class recursive_directory_iterator ([[fs.class.rec.dir.itr]](#fs.class.rec.dir.itr "31.12.12 Class recursive_­directory_­iterator"))[.](#fs.class.directory.iterator.general-1.sentence-2)

â *end note*]

namespace std::filesystem {class directory_iterator {public:using iterator_category = input_iterator_tag; using value_type = directory_entry; using difference_type = ptrdiff_t; using pointer = const directory_entry*; using reference = const directory_entry&; // [[fs.dir.itr.members]](#fs.dir.itr.members "31.12.11.2 Members"), member functions directory_iterator() noexcept; explicit directory_iterator(const path& p);
 directory_iterator(const path& p, directory_options options);
 directory_iterator(const path& p, error_code& ec);
 directory_iterator(const path& p, directory_options options,
 error_code& ec);
 directory_iterator(const directory_iterator& rhs);
 directory_iterator(directory_iterator&& rhs) noexcept; ~directory_iterator();

 directory_iterator& operator=(const directory_iterator& rhs);
 directory_iterator& operator=(directory_iterator&& rhs) noexcept; const directory_entry& operator*() const; const directory_entry* operator->() const;
 directory_iterator& operator++();
 directory_iterator& increment(error_code& ec); bool operator==(default_sentinel_t) const noexcept {return *this == directory_iterator(); }// other members as required by [[input.iterators]](input.iterators "24.3.5.3 Input iterators"), input iterators};}

[2](#fs.class.directory.iterator.general-2)

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

directory_iterator meets the[*Cpp17InputIterator*](input.iterators#:Cpp17InputIterator "24.3.5.3 Input iterators [input.iterators]") requirements ([[input.iterators]](input.iterators "24.3.5.3 Input iterators"))[.](#fs.class.directory.iterator.general-2.sentence-1)

[3](#fs.class.directory.iterator.general-3)

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

If an iterator of type directory_iterator reports an error or
is advanced past the last directory element,
that iterator shall become equal to the end iterator
value[.](#fs.class.directory.iterator.general-3.sentence-1)

The directory_iterator default constructor shall
create an iterator equal to the end iterator value, and this shall be the only
valid iterator for the end condition[.](#fs.class.directory.iterator.general-3.sentence-2)

[4](#fs.class.directory.iterator.general-4)

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

The end iterator is not dereferenceable[.](#fs.class.directory.iterator.general-4.sentence-1)

[5](#fs.class.directory.iterator.general-5)

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

Two end iterators are always equal[.](#fs.class.directory.iterator.general-5.sentence-1)

An end iterator shall not be equal to a non-end
iterator[.](#fs.class.directory.iterator.general-5.sentence-2)

[6](#fs.class.directory.iterator.general-6)

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

The result of calling the path() member of the directory_entry object obtained by dereferencing a directory_iterator is a reference to a path object composed of the directory argument from which the iterator was
constructed with the filename of the directory entry appended as if by operator/=[.](#fs.class.directory.iterator.general-6.sentence-1)

[7](#fs.class.directory.iterator.general-7)

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

Directory iteration shall not yield directory entries for the current (dot)
and parent (dot-dot) directories[.](#fs.class.directory.iterator.general-7.sentence-1)

[8](#fs.class.directory.iterator.general-8)

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

The order of directory entries obtained by dereferencing successive
increments of a directory_iterator is unspecified[.](#fs.class.directory.iterator.general-8.sentence-1)

[9](#fs.class.directory.iterator.general-9)

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

Constructors and non-const directory_iterator member functions
store the values of any cached attributes ([[fs.class.directory.entry]](#fs.class.directory.entry "31.12.10 Class directory_­entry"))
in the directory_entry element returned by operator*()[.](#fs.class.directory.iterator.general-9.sentence-1)

directory_iterator member functions shall not directly or indirectly call
any directory_entry refresh function[.](#fs.class.directory.iterator.general-9.sentence-2)

[*Note [2](#fs.class.directory.iterator.general-note-2)*:

The exact mechanism for storing cached attribute values is not exposed to users[.](#fs.class.directory.iterator.general-9.sentence-3)

â *end note*]

[10](#fs.class.directory.iterator.general-10)

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

[*Note [3](#fs.class.directory.iterator.general-note-3)*:

A path obtained by dereferencing a directory iterator might not actually exist;
it could be a symbolic link to a non-existent file[.](#fs.class.directory.iterator.general-10.sentence-1)

Recursively walking directory trees
for purposes of removing and renaming entries
might invalidate symbolic links that are being followed[.](#fs.class.directory.iterator.general-10.sentence-2)

â *end note*]

[11](#fs.class.directory.iterator.general-11)

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

[*Note [4](#fs.class.directory.iterator.general-note-4)*:

If a file is removed from or added to a directory after the
construction of a directory_iterator for the directory, it is
unspecified whether or not subsequently incrementing the iterator will ever
result in an iterator referencing the removed or added directory entry[.](#fs.class.directory.iterator.general-11.sentence-1)

See
POSIX [readdir](http://pubs.opengroup.org/onlinepubs/9699919799/functions/readdir.html)[.](#fs.class.directory.iterator.general-11.sentence-2)

â *end note*]

#### [31.12.11.2](#fs.dir.itr.members) Members [[fs.dir.itr.members]](fs.dir.itr.members)

[ð](#lib:directory_iterator,constructor)

`directory_iterator() noexcept;
`

[1](#fs.dir.itr.members-1)

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

*Effects*: Constructs the end iterator[.](#fs.dir.itr.members-1.sentence-1)

[ð](#lib:directory_iterator,constructor_)

`explicit directory_iterator(const path& p);
directory_iterator(const path& p, directory_options options);
directory_iterator(const path& p, error_code& ec);
directory_iterator(const path& p, directory_options options, error_code& ec);
`

[2](#fs.dir.itr.members-2)

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

*Effects*: For the directory that p resolves to, constructs an
iterator for the first element in a sequence of directory_entry elements representing the files in the directory, if any; otherwise the end
iterator[.](#fs.dir.itr.members-2.sentence-1)

However, if(options & directory_options::skip_permission_denied) != directory_options::none and construction encounters an error indicating
that permission to access p is denied, constructs the end iterator
and does not report an error[.](#fs.dir.itr.members-2.sentence-2)

[3](#fs.dir.itr.members-3)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.dir.itr.members-3.sentence-1)

[4](#fs.dir.itr.members-4)

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

[*Note [1](#fs.dir.itr.members-note-1)*:

To iterate over the current directory, use directory_iterator(".") rather than directory_iterator("")[.](#fs.dir.itr.members-4.sentence-1)

â *end note*]

[ð](#lib:directory_iterator,constructor__)

`directory_iterator(const directory_iterator& rhs);
directory_iterator(directory_iterator&& rhs) noexcept;
`

[5](#fs.dir.itr.members-5)

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

*Postconditions*: *this has the original value of rhs[.](#fs.dir.itr.members-5.sentence-1)

[ð](#lib:operator=,directory_iterator)

`directory_iterator& operator=(const directory_iterator& rhs);
directory_iterator& operator=(directory_iterator&& rhs) noexcept;
`

[6](#fs.dir.itr.members-6)

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

*Effects*: If *this and rhs are the same
 object, the member has no effect[.](#fs.dir.itr.members-6.sentence-1)

[7](#fs.dir.itr.members-7)

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

*Postconditions*: *this has the original value of rhs[.](#fs.dir.itr.members-7.sentence-1)

[8](#fs.dir.itr.members-8)

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

*Returns*: *this[.](#fs.dir.itr.members-8.sentence-1)

[ð](#lib:increment,directory_iterator)

`directory_iterator& operator++();
directory_iterator& increment(error_code& ec);
`

[9](#fs.dir.itr.members-9)

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

*Effects*: As specified for the prefix increment operation of[Input iterators](input.iterators "24.3.5.3 Input iterators [input.iterators]")[.](#fs.dir.itr.members-9.sentence-1)

[10](#fs.dir.itr.members-10)

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

*Returns*: *this[.](#fs.dir.itr.members-10.sentence-1)

[11](#fs.dir.itr.members-11)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.dir.itr.members-11.sentence-1)

#### [31.12.11.3](#fs.dir.itr.nonmembers) Non-member functions [[fs.dir.itr.nonmembers]](fs.dir.itr.nonmembers)

[1](#fs.dir.itr.nonmembers-1)

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

These functions enable range access for directory_iterator[.](#fs.dir.itr.nonmembers-1.sentence-1)

[ð](#lib:begin,directory_iterator)

`directory_iterator begin(directory_iterator iter) noexcept;
`

[2](#fs.dir.itr.nonmembers-2)

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

*Returns*: iter[.](#fs.dir.itr.nonmembers-2.sentence-1)

[ð](#lib:end,directory_iterator)

`directory_iterator end(directory_iterator) noexcept;
`

[3](#fs.dir.itr.nonmembers-3)

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

*Returns*: directory_iterator()[.](#fs.dir.itr.nonmembers-3.sentence-1)

### [31.12.12](#fs.class.rec.dir.itr) Class recursive_directory_iterator [[fs.class.rec.dir.itr]](fs.class.rec.dir.itr)

#### [31.12.12.1](#fs.class.rec.dir.itr.general) General [[fs.class.rec.dir.itr.general]](fs.class.rec.dir.itr.general)

[1](#fs.class.rec.dir.itr.general-1)

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

An object of type recursive_directory_iterator provides an iterator for
a sequence of directory_entry elements representing the files in a
directory or in an implementation-defined directory-like file
type, and its subdirectories[.](#fs.class.rec.dir.itr.general-1.sentence-1)

namespace std::filesystem {class recursive_directory_iterator {public:using iterator_category = input_iterator_tag; using value_type = directory_entry; using difference_type = ptrdiff_t; using pointer = const directory_entry*; using reference = const directory_entry&; // [[fs.rec.dir.itr.members]](#fs.rec.dir.itr.members "31.12.12.2 Members"), constructors and destructor recursive_directory_iterator() noexcept; explicit recursive_directory_iterator(const path& p);
 recursive_directory_iterator(const path& p, directory_options options);
 recursive_directory_iterator(const path& p, directory_options options,
 error_code& ec);
 recursive_directory_iterator(const path& p, error_code& ec);
 recursive_directory_iterator(const recursive_directory_iterator& rhs);
 recursive_directory_iterator(recursive_directory_iterator&& rhs) noexcept; ~recursive_directory_iterator(); // [[fs.rec.dir.itr.members]](#fs.rec.dir.itr.members "31.12.12.2 Members"), observers directory_options options() const; int depth() const; bool recursion_pending() const; const directory_entry& operator*() const; const directory_entry* operator->() const; // [[fs.rec.dir.itr.members]](#fs.rec.dir.itr.members "31.12.12.2 Members"), modifiers recursive_directory_iterator&operator=(const recursive_directory_iterator& rhs);
 recursive_directory_iterator&operator=(recursive_directory_iterator&& rhs) noexcept;

 recursive_directory_iterator& operator++();
 recursive_directory_iterator& increment(error_code& ec); void pop(); void pop(error_code& ec); void disable_recursion_pending(); bool operator==(default_sentinel_t) const noexcept {return *this == recursive_directory_iterator(); }// other members as required by [[input.iterators]](input.iterators "24.3.5.3 Input iterators"), input iterators};}

[2](#fs.class.rec.dir.itr.general-2)

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

Calling options, depth, recursion_pending,pop or disable_recursion_pending on an iterator that is not dereferenceable results in undefined behavior[.](#fs.class.rec.dir.itr.general-2.sentence-1)

[3](#fs.class.rec.dir.itr.general-3)

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

The behavior of a recursive_directory_iterator is the same
as a directory_iterator unless otherwise specified[.](#fs.class.rec.dir.itr.general-3.sentence-1)

[4](#fs.class.rec.dir.itr.general-4)

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

[*Note [1](#fs.class.rec.dir.itr.general-note-1)*:

If the directory structure being iterated over contains cycles
then it is possible that the end iterator is unreachable[.](#fs.class.rec.dir.itr.general-4.sentence-1)

â *end note*]

#### [31.12.12.2](#fs.rec.dir.itr.members) Members [[fs.rec.dir.itr.members]](fs.rec.dir.itr.members)

[ð](#lib:recursive_directory_iterator,constructor)

`recursive_directory_iterator() noexcept;
`

[1](#fs.rec.dir.itr.members-1)

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

*Effects*: Constructs the end iterator[.](#fs.rec.dir.itr.members-1.sentence-1)

[ð](#lib:recursive_directory_iterator,constructor_)

`explicit recursive_directory_iterator(const path& p);
recursive_directory_iterator(const path& p, directory_options options);
recursive_directory_iterator(const path& p, directory_options options, error_code& ec);
recursive_directory_iterator(const path& p, error_code& ec);
`

[2](#fs.rec.dir.itr.members-2)

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

*Effects*: Constructs an iterator representing the first
entry in the directory to which p resolves, if any; otherwise, the end iterator[.](#fs.rec.dir.itr.members-2.sentence-1)

However, if(options & directory_options::skip_permission_denied) != directory_options::none and construction encounters an error indicating
that permission to access p is denied, constructs the end iterator
and does not report an error[.](#fs.rec.dir.itr.members-2.sentence-2)

[3](#fs.rec.dir.itr.members-3)

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

*Postconditions*: options() == options for the signatures with adirectory_options argument, otherwise options() == directory_options​::​none[.](#fs.rec.dir.itr.members-3.sentence-1)

[4](#fs.rec.dir.itr.members-4)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.rec.dir.itr.members-4.sentence-1)

[5](#fs.rec.dir.itr.members-5)

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

[*Note [1](#fs.rec.dir.itr.members-note-1)*:

Use recursive_directory_iterator(".") rather than recursive_directory_iterator("") to iterate over the current directory[.](#fs.rec.dir.itr.members-5.sentence-1)

â *end note*]

[6](#fs.rec.dir.itr.members-6)

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

[*Note [2](#fs.rec.dir.itr.members-note-2)*:

By default, recursive_directory_iterator does not
follow directory symlinks[.](#fs.rec.dir.itr.members-6.sentence-1)

To follow directory symlinks, specify options asdirectory_options​::​follow_directory_symlink[.](#fs.rec.dir.itr.members-6.sentence-2)

â *end note*]

[ð](#lib:recursive_directory_iterator,constructor__)

`recursive_directory_iterator(const recursive_directory_iterator& rhs);
`

[7](#fs.rec.dir.itr.members-7)

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

*Postconditions*: 

- [(7.1)](#fs.rec.dir.itr.members-7.1)

options() == rhs.options()

- [(7.2)](#fs.rec.dir.itr.members-7.2)

depth() == rhs.depth()

- [(7.3)](#fs.rec.dir.itr.members-7.3)

recursion_pending() == rhs.recursion_pending()

[ð](#lib:recursive_directory_iterator,constructor___)

`recursive_directory_iterator(recursive_directory_iterator&& rhs) noexcept;
`

[8](#fs.rec.dir.itr.members-8)

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

*Postconditions*: options(), depth(),
 and recursion_pending() have the values that rhs.options(), rhs.depth(), and rhs.recursion_pending(), respectively, had before the function call[.](#fs.rec.dir.itr.members-8.sentence-1)

[ð](#lib:operator=,recursive_directory_iterator)

`recursive_directory_iterator& operator=(const recursive_directory_iterator& rhs);
`

[9](#fs.rec.dir.itr.members-9)

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

*Effects*: If *this and rhs are the same
 object, the member has no effect[.](#fs.rec.dir.itr.members-9.sentence-1)

[10](#fs.rec.dir.itr.members-10)

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

*Postconditions*: 

- [(10.1)](#fs.rec.dir.itr.members-10.1)

options() == rhs.options()

- [(10.2)](#fs.rec.dir.itr.members-10.2)

depth() == rhs.depth()

- [(10.3)](#fs.rec.dir.itr.members-10.3)

recursion_pending() == rhs.recursion_pending()

[11](#fs.rec.dir.itr.members-11)

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

*Returns*: *this[.](#fs.rec.dir.itr.members-11.sentence-1)

[ð](#lib:operator=,recursive_directory_iterator_)

`recursive_directory_iterator& operator=(recursive_directory_iterator&& rhs) noexcept;
`

[12](#fs.rec.dir.itr.members-12)

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

*Effects*: If *this and rhs are the same
object, the member has no effect[.](#fs.rec.dir.itr.members-12.sentence-1)

[13](#fs.rec.dir.itr.members-13)

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

*Postconditions*: options(), depth(),
and recursion_pending() have the values that rhs.options(),rhs.depth(), and rhs.recursion_pending(), respectively, had before the function call[.](#fs.rec.dir.itr.members-13.sentence-1)

[14](#fs.rec.dir.itr.members-14)

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

*Returns*: *this[.](#fs.rec.dir.itr.members-14.sentence-1)

[ð](#lib:options,recursive_directory_iterator)

`directory_options options() const;
`

[15](#fs.rec.dir.itr.members-15)

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

*Returns*: The value of the argument passed to the constructor for theoptions parameter, if present, otherwisedirectory_options​::​none[.](#fs.rec.dir.itr.members-15.sentence-1)

[16](#fs.rec.dir.itr.members-16)

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

*Throws*: Nothing[.](#fs.rec.dir.itr.members-16.sentence-1)

[ð](#lib:depth,recursive_directory_iterator)

`int depth() const;
`

[17](#fs.rec.dir.itr.members-17)

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

*Returns*: The current depth of the directory tree being traversed[.](#fs.rec.dir.itr.members-17.sentence-1)

[*Note [3](#fs.rec.dir.itr.members-note-3)*:

The initial directory is depth 0, its immediate subdirectories are depth 1,
 and so forth[.](#fs.rec.dir.itr.members-17.sentence-2)

â *end note*]

[18](#fs.rec.dir.itr.members-18)

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

*Throws*: Nothing[.](#fs.rec.dir.itr.members-18.sentence-1)

[ð](#lib:recursion_pending,recursive_directory_iterator)

`bool recursion_pending() const;
`

[19](#fs.rec.dir.itr.members-19)

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

*Returns*: true if disable_recursion_pending() has not been called subsequent to the prior construction or increment
 operation, otherwise false[.](#fs.rec.dir.itr.members-19.sentence-1)

[20](#fs.rec.dir.itr.members-20)

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

*Throws*: Nothing[.](#fs.rec.dir.itr.members-20.sentence-1)

[ð](#lib:increment,recursive_directory_iterator)

`recursive_directory_iterator& operator++();
recursive_directory_iterator& increment(error_code& ec);
`

[21](#fs.rec.dir.itr.members-21)

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

*Effects*: As specified for the prefix increment operation of[Input iterators](input.iterators "24.3.5.3 Input iterators [input.iterators]"),
except that:

- [(21.1)](#fs.rec.dir.itr.members-21.1)

If there are no more entries at the current depth, then if depth() != 0 iteration over the parent directory resumes; otherwise *this = recursive_directory_iterator().

- [(21.2)](#fs.rec.dir.itr.members-21.2)

Otherwise ifrecursion_pending() && is_directory((*this)->status()) &&(!is_symlink((*this)->symlink_status()) ||(options() & directory_options::follow_directory_symlink) != directory_options::none) then either directory (*this)->path() is recursively iterated into or,
if(options() & directory_options::skip_permission_denied) != directory_options::none and an error occurs indicating that permission to access directory (*this)->path() is denied,
then directory (*this)->path() is
treated as an empty directory and no error is reported.

[22](#fs.rec.dir.itr.members-22)

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

*Returns*: *this[.](#fs.rec.dir.itr.members-22.sentence-1)

[23](#fs.rec.dir.itr.members-23)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.rec.dir.itr.members-23.sentence-1)

[ð](#lib:pop,recursive_directory_iterator)

`void pop();
void pop(error_code& ec);
`

[24](#fs.rec.dir.itr.members-24)

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

*Effects*: If depth() == 0, set *this to recursive_directory_iterator()[.](#fs.rec.dir.itr.members-24.sentence-1)

Otherwise, cease iteration of the directory currently being
 iterated over, and continue iteration over the parent directory[.](#fs.rec.dir.itr.members-24.sentence-2)

[25](#fs.rec.dir.itr.members-25)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.rec.dir.itr.members-25.sentence-1)

[26](#fs.rec.dir.itr.members-26)

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

*Remarks*: Any copies of the previous value of *this are no longer required
to be dereferenceable nor to be in the domain of ==[.](#fs.rec.dir.itr.members-26.sentence-1)

[ð](#lib:disable_recursion_pending,recursive_directory_iterator)

`void disable_recursion_pending();
`

[27](#fs.rec.dir.itr.members-27)

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

*Postconditions*: recursion_pending() == false[.](#fs.rec.dir.itr.members-27.sentence-1)

[28](#fs.rec.dir.itr.members-28)

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

[*Note [4](#fs.rec.dir.itr.members-note-4)*:

disable_recursion_pending() is used to prevent
 unwanted recursion into a directory[.](#fs.rec.dir.itr.members-28.sentence-1)

â *end note*]

#### [31.12.12.3](#fs.rec.dir.itr.nonmembers) Non-member functions [[fs.rec.dir.itr.nonmembers]](fs.rec.dir.itr.nonmembers)

[1](#fs.rec.dir.itr.nonmembers-1)

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

These functions enable use of recursive_directory_iterator with range-based for statements[.](#fs.rec.dir.itr.nonmembers-1.sentence-1)

[ð](#lib:begin,recursive_directory_iterator)

`recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept;
`

[2](#fs.rec.dir.itr.nonmembers-2)

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

*Returns*: iter[.](#fs.rec.dir.itr.nonmembers-2.sentence-1)

[ð](#lib:end,recursive_directory_iterator)

`recursive_directory_iterator end(recursive_directory_iterator) noexcept;
`

[3](#fs.rec.dir.itr.nonmembers-3)

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

*Returns*: recursive_directory_iterator()[.](#fs.rec.dir.itr.nonmembers-3.sentence-1)

### [31.12.13](#fs.op.funcs) Filesystem operation functions [[fs.op.funcs]](fs.op.funcs)

#### [31.12.13.1](#fs.op.funcs.general) General [[fs.op.funcs.general]](fs.op.funcs.general)

[1](#fs.op.funcs.general-1)

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

Filesystem operation functions query or modify files, including directories,
in external storage[.](#fs.op.funcs.general-1.sentence-1)

[2](#fs.op.funcs.general-2)

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

[*Note [1](#fs.op.funcs.general-note-1)*:

Because hardware failures, network failures, file system races ([[fs.race.behavior]](#fs.race.behavior "31.12.2.4 File system race behavior")),
and many other kinds of errors occur frequently in file system operations,
any filesystem operation function, no matter how apparently innocuous,
can encounter an error; see [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.funcs.general-2.sentence-1)

â *end note*]

#### [31.12.13.2](#fs.op.absolute) Absolute [[fs.op.absolute]](fs.op.absolute)

[ð](#lib:absolute)

`path filesystem::absolute(const path& p);
path filesystem::absolute(const path& p, error_code& ec);
`

[1](#fs.op.absolute-1)

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

*Effects*: Composes an absolute path referencing the same file system location
as p according to the operating system ([[fs.conform.os]](#fs.conform.os "31.12.2.3 Operating system dependent behavior conformance"))[.](#fs.op.absolute-1.sentence-1)

[2](#fs.op.absolute-2)

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

*Returns*: The composed path[.](#fs.op.absolute-2.sentence-1)

The signature with argument ec returns path() if an error occurs[.](#fs.op.absolute-2.sentence-2)

[3](#fs.op.absolute-3)

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

[*Note [1](#fs.op.absolute-note-1)*:

For the returned path, rp, rp.is_absolute() is true unless an error occurs[.](#fs.op.absolute-3.sentence-1)

â *end note*]

[4](#fs.op.absolute-4)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.absolute-4.sentence-1)

[5](#fs.op.absolute-5)

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

[*Note [2](#fs.op.absolute-note-2)*:

To resolve symlinks
or perform other sanitization that can involve queries to secondary storage,
such as hard disks, consider canonical ([[fs.op.canonical]](#fs.op.canonical "31.12.13.3 Canonical"))[.](#fs.op.absolute-5.sentence-1)

â *end note*]

[6](#fs.op.absolute-6)

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

[*Note [3](#fs.op.absolute-note-3)*:

Implementations are strongly encouraged to not query secondary storage,
and not consider !exists(p) an error[.](#fs.op.absolute-6.sentence-1)

â *end note*]

[7](#fs.op.absolute-7)

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

[*Example [1](#fs.op.absolute-example-1)*:

For POSIX-based operating systems,absolute(p) is simply current_path()/p[.](#fs.op.absolute-7.sentence-1)

For Windows-based operating systems,absolute might have the same semantics as GetFullPathNameW[.](#fs.op.absolute-7.sentence-2)

â *end example*]

#### [31.12.13.3](#fs.op.canonical) Canonical [[fs.op.canonical]](fs.op.canonical)

[ð](#lib:canonical)

`path filesystem::canonical(const path& p);
path filesystem::canonical(const path& p, error_code& ec);
`

[1](#fs.op.canonical-1)

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

*Effects*: Converts p to an absolute
path that has no symbolic link, dot, or dot-dot elements
in its pathname in the generic format[.](#fs.op.canonical-1.sentence-1)

[2](#fs.op.canonical-2)

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

*Returns*: A path that refers to
the same file system object as absolute(p)[.](#fs.op.canonical-2.sentence-1)

The signature with argument ec returns path() if an error occurs[.](#fs.op.canonical-2.sentence-2)

[3](#fs.op.canonical-3)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.canonical-3.sentence-1)

[4](#fs.op.canonical-4)

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

*Remarks*: !exists(p) is an error[.](#fs.op.canonical-4.sentence-1)

#### [31.12.13.4](#fs.op.copy) Copy [[fs.op.copy]](fs.op.copy)

[ð](#lib:copy,path)

`void filesystem::copy(const path& from, const path& to);
`

[1](#fs.op.copy-1)

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

*Effects*: Equivalent tocopy(from, to, copy_options​::​none)[.](#fs.op.copy-1.sentence-1)

[ð](#lib:copy,path_)

`void filesystem::copy(const path& from, const path& to, error_code& ec);
`

[2](#fs.op.copy-2)

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

*Effects*: Equivalent tocopy(from, to, copy_options​::​none, ec)[.](#fs.op.copy-2.sentence-1)

[ð](#lib:copy,path__)

`void filesystem::copy(const path& from, const path& to, copy_options options);
void filesystem::copy(const path& from, const path& to, copy_options options,
                      error_code& ec);
`

[3](#fs.op.copy-3)

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

*Preconditions*: At most one element from each option group ([[fs.enum.copy.opts]](#fs.enum.copy.opts "31.12.8.3 Enum class copy_­options"))
is set in options[.](#fs.op.copy-3.sentence-1)

[4](#fs.op.copy-4)

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

*Effects*: Before the first use of f and t:

- [(4.1)](#fs.op.copy-4.1)

If(options & copy_options::create_symlinks) != copy_options::none ||(options & copy_options::skip_symlinks) != copy_options::none then auto f = symlink_status(from) and if needed auto t = symlink_status(to).

- [(4.2)](#fs.op.copy-4.2)

Otherwise, if(options & copy_options::copy_symlinks) != copy_options::none then auto f = symlink_status(from) and if needed auto t = status(to).

- [(4.3)](#fs.op.copy-4.3)

Otherwise, auto f = status(from) and if needed auto t = status(to).

Effects are then as follows:

- [(4.4)](#fs.op.copy-4.4)

  If f.type() or t.type() is an implementation-defined
file type ([[fs.enum.file.type]](#fs.enum.file.type "31.12.8.2 Enum class file_­type")), then the effects areimplementation-defined[.](#fs.op.copy-4.4.sentence-1)

- [(4.5)](#fs.op.copy-4.5)

  Otherwise, an error is reported as specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting") if
  * [(4.5.1)](#fs.op.copy-4.5.1)

exists(f) is false, or

  * [(4.5.2)](#fs.op.copy-4.5.2)

equivalent(from, to) is true, or

  * [(4.5.3)](#fs.op.copy-4.5.3)

is_other(f) || is_other(t) is true, or

  * [(4.5.4)](#fs.op.copy-4.5.4)

is_directory(f) && is_regular_file(t) is true[.](#fs.op.copy-4.5.sentence-1)

- [(4.6)](#fs.op.copy-4.6)

  Otherwise, if is_symlink(f), then:
  * [(4.6.1)](#fs.op.copy-4.6.1)

      If(options & copy_options​::​skip_symlinks) != copy_options​::​none then return[.](#fs.op.copy-4.6.1.sentence-1)

  * [(4.6.2)](#fs.op.copy-4.6.2)

      Otherwise if!exists(t) && (options & copy_options::copy_symlinks) != copy_options::none then copy_symlink(from, to)[.](#fs.op.copy-4.6.2.sentence-1)

  * [(4.6.3)](#fs.op.copy-4.6.3)

      Otherwise report an error as specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.copy-4.6.3.sentence-1)

- [(4.7)](#fs.op.copy-4.7)

  Otherwise, if is_regular_file(f), then:
  * [(4.7.1)](#fs.op.copy-4.7.1)

      If (options & copy_options​::​directories_only) != copy_options​::​none, then return[.](#fs.op.copy-4.7.1.sentence-1)

  * [(4.7.2)](#fs.op.copy-4.7.2)

      Otherwise, if (options & copy_options​::​create_symlinks)  != copy_options​::​none, then create a symbolic link to the
 source file[.](#fs.op.copy-4.7.2.sentence-1)

  * [(4.7.3)](#fs.op.copy-4.7.3)

      Otherwise, if (options & copy_options​::​create_hard_links) != copy_options​::​none,
 then create a hard link to the source file[.](#fs.op.copy-4.7.3.sentence-1)

  * [(4.7.4)](#fs.op.copy-4.7.4)

      Otherwise, if is_directory(t), then copy_file(from, to/from.filename(), options)[.](#fs.op.copy-4.7.4.sentence-1)

  * [(4.7.5)](#fs.op.copy-4.7.5)

      Otherwise, copy_file(from, to, options)[.](#fs.op.copy-4.7.5.sentence-1)

- [(4.8)](#fs.op.copy-4.8)

  Otherwise, ifis_directory(f) &&(options & copy_options::create_symlinks) != copy_options::none then report an error with an error_code argument
equal to make_error_code(errc​::​is_a_directory)[.](#fs.op.copy-4.8.sentence-1)

- [(4.9)](#fs.op.copy-4.9)

  Otherwise, ifis_directory(f) &&((options & copy_options::recursive) != copy_options::none || options == copy_options::none) then:
  * [(4.9.1)](#fs.op.copy-4.9.1)

If exists(t) is false, then create_directory(to, from).

  * [(4.9.2)](#fs.op.copy-4.9.2)

Then, iterate over the files in from, as if byfor (const directory_entry& x : directory_iterator(from)) copy(x.path(), to/x.path().filename(),
 options | copy_options::*in-recursive-copy*); where *in-recursive-copy* is a bitmask element of copy_options that is not one of the elements in [[fs.enum.copy.opts]](#fs.enum.copy.opts "31.12.8.3 Enum class copy_­options").

- [(4.10)](#fs.op.copy-4.10)

  Otherwise, for the signature with argument ec, ec.clear()[.](#fs.op.copy-4.10.sentence-1)

- [(4.11)](#fs.op.copy-4.11)

  Otherwise, no effects[.](#fs.op.copy-4.11.sentence-1)

[5](#fs.op.copy-5)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.copy-5.sentence-1)

[6](#fs.op.copy-6)

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

*Remarks*: For the signature with argument ec, any
library functions called by the implementation shall have an error_code argument if applicable[.](#fs.op.copy-6.sentence-1)

[7](#fs.op.copy-7)

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

[*Example [1](#fs.op.copy-example-1)*:

Given this directory structure:

```
/dir1
  file1
  file2
  dir2
    file3

```

Calling copy("/dir1", "/dir3") would result in:

```
/dir1
  file1
  file2
  dir2
    file3
/dir3
  file1
  file2

```

Alternatively, calling copy("/dir1", "/dir3", copy_options​::​recursive) would result in:

```
/dir1
  file1
  file2
  dir2
    file3
/dir3
  file1
  file2
  dir2
    file3

```

â *end example*]

#### [31.12.13.5](#fs.op.copy.file) Copy file [[fs.op.copy.file]](fs.op.copy.file)

[ð](#lib:copy_file)

`bool filesystem::copy_file(const path& from, const path& to);
bool filesystem::copy_file(const path& from, const path& to, error_code& ec);
`

[1](#fs.op.copy.file-1)

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

*Returns*: copy_file(from, to, copy_options​::​none) or  

copy_file(from, to, copy_options​::​none, ec), respectively[.](#fs.op.copy.file-1.sentence-2)

[2](#fs.op.copy.file-2)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.copy.file-2.sentence-1)

[ð](#lib:copy_file_)

`bool filesystem::copy_file(const path& from, const path& to, copy_options options);
bool filesystem::copy_file(const path& from, const path& to, copy_options options,
                           error_code& ec);
`

[3](#fs.op.copy.file-3)

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

*Preconditions*: At most one element from each
option group ([[fs.enum.copy.opts]](#fs.enum.copy.opts "31.12.8.3 Enum class copy_­options")) is set
in options[.](#fs.op.copy.file-3.sentence-1)

[4](#fs.op.copy.file-4)

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

*Effects*: As follows:

- [(4.1)](#fs.op.copy.file-4.1)

  Report an error as specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting") if
  * [(4.1.1)](#fs.op.copy.file-4.1.1)

is_regular_file(from) is false, or

  * [(4.1.2)](#fs.op.copy.file-4.1.2)

exists(to) is true and is_regular_file(to) is false, or

  * [(4.1.3)](#fs.op.copy.file-4.1.3)

exists(to) is true and equivalent(from, to) is true, or

  * [(4.1.4)](#fs.op.copy.file-4.1.4)

exists(to) is true and(options & (copy_options::skip_existing | copy_options::overwrite_existing | copy_options::update_existing)) == copy_options::none

- [(4.2)](#fs.op.copy.file-4.2)

  Otherwise, copy the contents and attributes of the file from resolves to, to the file to resolves to, if
  * [(4.2.1)](#fs.op.copy.file-4.2.1)

exists(to) is false, or

  * [(4.2.2)](#fs.op.copy.file-4.2.2)

(options & copy_options​::​overwrite_existing) != copy_options​::​none, or

  * [(4.2.3)](#fs.op.copy.file-4.2.3)

(options & copy_options​::​update_existing)   != copy_options​::​none and from is more recent than to, determined as if by use of the last_write_time function ([[fs.op.last.write.time]](#fs.op.last.write.time "31.12.13.26 Last write time"))[.](#fs.op.copy.file-4.2.sentence-1)

- [(4.3)](#fs.op.copy.file-4.3)

  Otherwise, no effects[.](#fs.op.copy.file-4.3.sentence-1)

[5](#fs.op.copy.file-5)

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

*Returns*: true if the from file
 was copied, otherwise false[.](#fs.op.copy.file-5.sentence-1)

The signature with argument ec returns false if an error occurs[.](#fs.op.copy.file-5.sentence-2)

[6](#fs.op.copy.file-6)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.copy.file-6.sentence-1)

[7](#fs.op.copy.file-7)

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

*Complexity*: At most one direct or indirect invocation of status(to)[.](#fs.op.copy.file-7.sentence-1)

#### [31.12.13.6](#fs.op.copy.symlink) Copy symlink [[fs.op.copy.symlink]](fs.op.copy.symlink)

[ð](#lib:copy_symlink)

`void filesystem::copy_symlink(const path& existing_symlink, const path& new_symlink);
void filesystem::copy_symlink(const path& existing_symlink, const path& new_symlink,
                              error_code& ec) noexcept;
`

[1](#fs.op.copy.symlink-1)

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

*Effects*: Equivalent to*function*(read_symlink(existing_symlink), new_symlink) or  

*function*(read_symlink(existing_symlink, ec), new_symlink, ec), respectively,
 where in each case *function* is create_symlink or create_directory_symlink as appropriate[.](#fs.op.copy.symlink-1.sentence-2)

[2](#fs.op.copy.symlink-2)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.copy.symlink-2.sentence-1)

#### [31.12.13.7](#fs.op.create.directories) Create directories [[fs.op.create.directories]](fs.op.create.directories)

[ð](#lib:create_directories)

`bool filesystem::create_directories(const path& p);
bool filesystem::create_directories(const path& p, error_code& ec);
`

[1](#fs.op.create.directories-1)

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

*Effects*: Calls create_directory for each element of p that does not exist[.](#fs.op.create.directories-1.sentence-1)

[2](#fs.op.create.directories-2)

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

*Returns*: true if a new directory was created
 for the directory p resolves to,
 otherwise false[.](#fs.op.create.directories-2.sentence-1)

[3](#fs.op.create.directories-3)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.create.directories-3.sentence-1)

[4](#fs.op.create.directories-4)

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

*Complexity*: O(n) where *n* is the number of elements
 of p[.](#fs.op.create.directories-4.sentence-1)

#### [31.12.13.8](#fs.op.create.directory) Create directory [[fs.op.create.directory]](fs.op.create.directory)

[ð](#lib:create_directory)

`bool filesystem::create_directory(const path& p);
bool filesystem::create_directory(const path& p, error_code& ec) noexcept;
`

[1](#fs.op.create.directory-1)

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

*Effects*: Creates the directory p resolves to,
 as if by POSIX mkdir with a second argument of static_cast<int>(perms​::​all)[.](#fs.op.create.directory-1.sentence-1)

If mkdir fails because p resolves to an existing directory,
 no error is reported[.](#fs.op.create.directory-1.sentence-2)

Otherwise on failure an error is reported[.](#fs.op.create.directory-1.sentence-3)

[2](#fs.op.create.directory-2)

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

*Returns*: true if a new directory was created, otherwise false[.](#fs.op.create.directory-2.sentence-1)

[3](#fs.op.create.directory-3)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.create.directory-3.sentence-1)

[ð](#lib:create_directory_)

`bool filesystem::create_directory(const path& p, const path& existing_p);
bool filesystem::create_directory(const path& p, const path& existing_p, error_code& ec) noexcept;
`

[4](#fs.op.create.directory-4)

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

*Effects*: Creates the
 directory p resolves to, with
 attributes copied from directory existing_p[.](#fs.op.create.directory-4.sentence-1)

The set of attributes
 copied is operating system dependent[.](#fs.op.create.directory-4.sentence-2)

If mkdir fails because p resolves to an existing directory,
 no error is reported[.](#fs.op.create.directory-4.sentence-3)

Otherwise on failure an error is reported[.](#fs.op.create.directory-4.sentence-4)

[*Note [1](#fs.op.create.directory-note-1)*:

For POSIX-based operating systems, the
 attributes are those copied by native API stat(existing_p.c_str(), &attributes_stat) followed by mkdir(p.c_str(), attributes_stat.st_mode)[.](#fs.op.create.directory-4.sentence-5)

For
 Windows-based operating systems, the attributes are those copied by native
 API CreateDirectoryExW(existing_p.c_str(), p.c_str(), 0)[.](#fs.op.create.directory-4.sentence-6)

â *end note*]

[5](#fs.op.create.directory-5)

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

*Returns*: true if a new directory was created
 with attributes copied from directory existing_p,
 otherwise false[.](#fs.op.create.directory-5.sentence-1)

[6](#fs.op.create.directory-6)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.create.directory-6.sentence-1)

#### [31.12.13.9](#fs.op.create.dir.symlk) Create directory symlink [[fs.op.create.dir.symlk]](fs.op.create.dir.symlk)

[ð](#lib:create_directory_symlink)

`void filesystem::create_directory_symlink(const path& to, const path& new_symlink);
void filesystem::create_directory_symlink(const path& to, const path& new_symlink,
                                          error_code& ec) noexcept;
`

[1](#fs.op.create.dir.symlk-1)

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

*Effects*: Establishes the postcondition, as if by POSIX [symlink](http://pubs.opengroup.org/onlinepubs/9699919799/functions/symlink.html)[.](#fs.op.create.dir.symlk-1.sentence-1)

[2](#fs.op.create.dir.symlk-2)

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

*Postconditions*: new_symlink resolves to a symbolic link file that
 contains an unspecified representation of to[.](#fs.op.create.dir.symlk-2.sentence-1)

[3](#fs.op.create.dir.symlk-3)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.create.dir.symlk-3.sentence-1)

[4](#fs.op.create.dir.symlk-4)

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

[*Note [1](#fs.op.create.dir.symlk-note-1)*:

Some operating systems require symlink creation to
identify that the link is to a directory[.](#fs.op.create.dir.symlk-4.sentence-1)

Thus, create_symlink (instead of create_directory_symlink)
cannot be used reliably to create directory symlinks[.](#fs.op.create.dir.symlk-4.sentence-2)

â *end note*]

[5](#fs.op.create.dir.symlk-5)

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

[*Note [2](#fs.op.create.dir.symlk-note-2)*:

Some operating systems do not support symbolic links at all or support
 them only for regular files[.](#fs.op.create.dir.symlk-5.sentence-1)

Some file systems (such as the FAT file system) do not
 support
 symbolic links regardless of the operating system[.](#fs.op.create.dir.symlk-5.sentence-2)

â *end note*]

#### [31.12.13.10](#fs.op.create.hard.lk) Create hard link [[fs.op.create.hard.lk]](fs.op.create.hard.lk)

[ð](#lib:create_hard_link)

`void filesystem::create_hard_link(const path& to, const path& new_hard_link);
void filesystem::create_hard_link(const path& to, const path& new_hard_link,
                                      error_code& ec) noexcept;
`

[1](#fs.op.create.hard.lk-1)

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

*Effects*: Establishes the postcondition, as if by POSIX link[.](#fs.op.create.hard.lk-1.sentence-1)

[2](#fs.op.create.hard.lk-2)

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

*Postconditions*: 

- [(2.1)](#fs.op.create.hard.lk-2.1)

exists(to) && exists(new_hard_link) && equivalent(to, new_hard_link)

- [(2.2)](#fs.op.create.hard.lk-2.2)

The contents of the file or directory to resolves to are unchanged[.](#fs.op.create.hard.lk-2.sentence-1)

[3](#fs.op.create.hard.lk-3)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.create.hard.lk-3.sentence-1)

[4](#fs.op.create.hard.lk-4)

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

[*Note [1](#fs.op.create.hard.lk-note-1)*:

Some operating systems do not support hard links at all or support
 them only for regular files[.](#fs.op.create.hard.lk-4.sentence-1)

Some file systems (such as the FAT file system)
 do not support hard links regardless of the operating system[.](#fs.op.create.hard.lk-4.sentence-2)

Some file systems limit the number of links per file[.](#fs.op.create.hard.lk-4.sentence-3)

â *end note*]

#### [31.12.13.11](#fs.op.create.symlink) Create symlink [[fs.op.create.symlink]](fs.op.create.symlink)

[ð](#lib:create_symlink)

`void filesystem::create_symlink(const path& to, const path& new_symlink);
void filesystem::create_symlink(const path& to, const path& new_symlink,
                    error_code& ec) noexcept;
`

[1](#fs.op.create.symlink-1)

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

*Effects*: Establishes the postcondition, as if by POSIX [symlink](http://pubs.opengroup.org/onlinepubs/9699919799/functions/symlink.html)[.](#fs.op.create.symlink-1.sentence-1)

[2](#fs.op.create.symlink-2)

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

*Postconditions*: new_symlink resolves to a symbolic link file that
 contains an unspecified representation of to[.](#fs.op.create.symlink-2.sentence-1)

[3](#fs.op.create.symlink-3)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.create.symlink-3.sentence-1)

[4](#fs.op.create.symlink-4)

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

[*Note [1](#fs.op.create.symlink-note-1)*:

Some operating systems do not support symbolic links at all or support
 them only for regular files[.](#fs.op.create.symlink-4.sentence-1)

Some file systems (such as the FAT file system) do not
 support symbolic links regardless of the operating system[.](#fs.op.create.symlink-4.sentence-2)

â *end note*]

#### [31.12.13.12](#fs.op.current.path) Current path [[fs.op.current.path]](fs.op.current.path)

[ð](#lib:current_path)

`path filesystem::current_path();
path filesystem::current_path(error_code& ec);
`

[1](#fs.op.current.path-1)

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

*Returns*: The absolute path of the current working directory,
 whose pathname in the native format is
 obtained as if by POSIX [getcwd](http://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html)[.](#fs.op.current.path-1.sentence-1)

The signature with argument ec returns path() if an
 error occurs[.](#fs.op.current.path-1.sentence-2)

[2](#fs.op.current.path-2)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.current.path-2.sentence-1)

[3](#fs.op.current.path-3)

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

*Remarks*: The current working directory is the directory, associated
 with the process, that is used as the starting location in pathname resolution
 for relative paths[.](#fs.op.current.path-3.sentence-1)

[4](#fs.op.current.path-4)

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

[*Note [1](#fs.op.current.path-note-1)*:

The current path as returned by many operating systems is a dangerous
 global variable and can be changed unexpectedly by third-party or system
 library functions, or by another thread[.](#fs.op.current.path-4.sentence-1)

â *end note*]

[ð](#lib:current_path_)

`void filesystem::current_path(const path& p);
void filesystem::current_path(const path& p, error_code& ec) noexcept;
`

[5](#fs.op.current.path-5)

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

*Effects*: Establishes the postcondition, as if by POSIX [chdir](http://pubs.opengroup.org/onlinepubs/9699919799/functions/chdir.html)[.](#fs.op.current.path-5.sentence-1)

[6](#fs.op.current.path-6)

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

*Postconditions*: equivalent(p, current_path())[.](#fs.op.current.path-6.sentence-1)

[7](#fs.op.current.path-7)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.current.path-7.sentence-1)

[8](#fs.op.current.path-8)

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

[*Note [2](#fs.op.current.path-note-2)*:

The current path for many operating systems is a dangerous
 global state and can be changed unexpectedly by third-party or system
 library functions, or by another thread[.](#fs.op.current.path-8.sentence-1)

â *end note*]

#### [31.12.13.13](#fs.op.equivalent) Equivalent [[fs.op.equivalent]](fs.op.equivalent)

[ð](#lib:equivalent)

`bool filesystem::equivalent(const path& p1, const path& p2);
bool filesystem::equivalent(const path& p1, const path& p2, error_code& ec) noexcept;
`

[1](#fs.op.equivalent-1)

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

Two paths are considered to resolve to the same file system entity if two
 candidate entities reside on the same device at the same location[.](#fs.op.equivalent-1.sentence-1)

[*Note [1](#fs.op.equivalent-note-1)*:

On POSIX platforms, this is
 determined as if by the values of the POSIX stat class,
 obtained as if by stat for the two paths, having equal st_dev values
 and equal st_ino values[.](#fs.op.equivalent-1.sentence-2)

â *end note*]

[2](#fs.op.equivalent-2)

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

*Returns*: true, if p1 and p2 resolve to the same file
 system entity, otherwise false[.](#fs.op.equivalent-2.sentence-1)

The signature with argument ec returns false if an error occurs[.](#fs.op.equivalent-2.sentence-2)

[3](#fs.op.equivalent-3)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.equivalent-3.sentence-1)

[4](#fs.op.equivalent-4)

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

*Remarks*: !exists(p1) || !exists(p2) is an error[.](#fs.op.equivalent-4.sentence-1)

#### [31.12.13.14](#fs.op.exists) Exists [[fs.op.exists]](fs.op.exists)

[ð](#lib:exists)

`bool filesystem::exists(file_status s) noexcept;
`

[1](#fs.op.exists-1)

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

*Returns*: status_known(s) && s.type() != file_type​::​not_found[.](#fs.op.exists-1.sentence-1)

[ð](#lib:exists_)

`bool filesystem::exists(const path& p);
bool filesystem::exists(const path& p, error_code& ec) noexcept;
`

[2](#fs.op.exists-2)

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

Let s be a file_status,
determined as if by status(p) or status(p, ec), respectively[.](#fs.op.exists-2.sentence-1)

[3](#fs.op.exists-3)

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

*Effects*: The signature with argument ec calls ec.clear() if status_known(s)[.](#fs.op.exists-3.sentence-1)

[4](#fs.op.exists-4)

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

*Returns*: exists(s)[.](#fs.op.exists-4.sentence-1)

[5](#fs.op.exists-5)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.exists-5.sentence-1)

#### [31.12.13.15](#fs.op.file.size) File size [[fs.op.file.size]](fs.op.file.size)

[ð](#lib:file_size)

`uintmax_t filesystem::file_size(const path& p);
uintmax_t filesystem::file_size(const path& p, error_code& ec) noexcept;
`

[1](#fs.op.file.size-1)

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

*Effects*: If exists(p) is false, an error is reported ([[fs.err.report]](#fs.err.report "31.12.5 Error reporting"))[.](#fs.op.file.size-1.sentence-1)

[2](#fs.op.file.size-2)

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

*Returns*: 

- [(2.1)](#fs.op.file.size-2.1)

  If is_regular_file(p), the size in bytes of the file p resolves to, determined as if by the value of the POSIX stat class member st_size obtained as if by POSIX [stat](http://pubs.opengroup.org/onlinepubs/9699919799/functions/stat.html)[.](#fs.op.file.size-2.1.sentence-1)

- [(2.2)](#fs.op.file.size-2.2)

  Otherwise, the result is implementation-defined[.](#fs.op.file.size-2.2.sentence-1)

The signature with argument ec returns static_cast<uintmax_t>(-1) if an error occurs[.](#fs.op.file.size-2.sentence-2)

[3](#fs.op.file.size-3)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.file.size-3.sentence-1)

#### [31.12.13.16](#fs.op.hard.lk.ct) Hard link count [[fs.op.hard.lk.ct]](fs.op.hard.lk.ct)

[ð](#lib:hard_link_count)

`uintmax_t filesystem::hard_link_count(const path& p);
uintmax_t filesystem::hard_link_count(const path& p, error_code& ec) noexcept;
`

[1](#fs.op.hard.lk.ct-1)

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

*Returns*: The number of hard links for p[.](#fs.op.hard.lk.ct-1.sentence-1)

The signature
 with argument ec returns static_cast<uintmax_t>(-1) if an error occurs[.](#fs.op.hard.lk.ct-1.sentence-2)

[2](#fs.op.hard.lk.ct-2)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.hard.lk.ct-2.sentence-1)

#### [31.12.13.17](#fs.op.is.block.file) Is block file [[fs.op.is.block.file]](fs.op.is.block.file)

[ð](#lib:is_block_file)

`bool filesystem::is_block_file(file_status s) noexcept;
`

[1](#fs.op.is.block.file-1)

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

*Returns*: s.type() == file_type​::​block[.](#fs.op.is.block.file-1.sentence-1)

[ð](#lib:is_block_file_)

`bool filesystem::is_block_file(const path& p);
bool filesystem::is_block_file(const path& p, error_code& ec) noexcept;
`

[2](#fs.op.is.block.file-2)

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

*Returns*: is_block_file(status(p)) or is_block_file(status(p, ec)), respectively[.](#fs.op.is.block.file-2.sentence-1)

The signature with argument ec returns false if an error occurs[.](#fs.op.is.block.file-2.sentence-2)

[3](#fs.op.is.block.file-3)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.is.block.file-3.sentence-1)

#### [31.12.13.18](#fs.op.is.char.file) Is character file [[fs.op.is.char.file]](fs.op.is.char.file)

[ð](#lib:is_character_file)

`bool filesystem::is_character_file(file_status s) noexcept;
`

[1](#fs.op.is.char.file-1)

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

*Returns*: s.type() == file_type​::​character[.](#fs.op.is.char.file-1.sentence-1)

[ð](#lib:is_character_file_)

`bool filesystem::is_character_file(const path& p);
bool filesystem::is_character_file(const path& p, error_code& ec) noexcept;
`

[2](#fs.op.is.char.file-2)

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

*Returns*: is_character_file(status(p)) or is_character_file(status(p, ec)),
 respectively[.](#fs.op.is.char.file-2.sentence-1)

  


The signature with argument ec returns false if an error occurs[.](#fs.op.is.char.file-2.sentence-2)

[3](#fs.op.is.char.file-3)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.is.char.file-3.sentence-1)

#### [31.12.13.19](#fs.op.is.directory) Is directory [[fs.op.is.directory]](fs.op.is.directory)

[ð](#lib:is_directory)

`bool filesystem::is_directory(file_status s) noexcept;
`

[1](#fs.op.is.directory-1)

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

*Returns*: s.type() == file_type​::​directory[.](#fs.op.is.directory-1.sentence-1)

[ð](#lib:is_directory_)

`bool filesystem::is_directory(const path& p);
bool filesystem::is_directory(const path& p, error_code& ec) noexcept;
`

[2](#fs.op.is.directory-2)

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

*Returns*: is_directory(status(p)) or is_directory(status(p, ec)),
 respectively[.](#fs.op.is.directory-2.sentence-1)

The signature with argument ec returns false if an error occurs[.](#fs.op.is.directory-2.sentence-2)

[3](#fs.op.is.directory-3)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.is.directory-3.sentence-1)

#### [31.12.13.20](#fs.op.is.empty) Is empty [[fs.op.is.empty]](fs.op.is.empty)

[ð](#lib:is_empty,function)

`bool filesystem::is_empty(const path& p);
bool filesystem::is_empty(const path& p, error_code& ec);
`

[1](#fs.op.is.empty-1)

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

*Effects*: 

- [(1.1)](#fs.op.is.empty-1.1)

  Determine file_status s,
 as if by status(p) or status(p, ec), respectively[.](#fs.op.is.empty-1.1.sentence-1)

- [(1.2)](#fs.op.is.empty-1.2)

  For the signature with argument ec,
 return false if an error occurred[.](#fs.op.is.empty-1.2.sentence-1)

- [(1.3)](#fs.op.is.empty-1.3)

  Otherwise, if is_directory(s):
  * [(1.3.1)](#fs.op.is.empty-1.3.1)

      Create a variable itr,
 as if by directory_iterator itr(p) or directory_iterator itr(p, ec), respectively[.](#fs.op.is.empty-1.3.1.sentence-1)

  * [(1.3.2)](#fs.op.is.empty-1.3.2)

      For the signature with argument ec,
 return false if an error occurred[.](#fs.op.is.empty-1.3.2.sentence-1)

  * [(1.3.3)](#fs.op.is.empty-1.3.3)

      Otherwise, return itr == directory_iterator()[.](#fs.op.is.empty-1.3.3.sentence-1)

- [(1.4)](#fs.op.is.empty-1.4)

  Otherwise:
  * [(1.4.1)](#fs.op.is.empty-1.4.1)

      Determine uintmax_t sz,
 as if by file_size(p) or file_size(p, ec), respectively[.](#fs.op.is.empty-1.4.1.sentence-1)

  * [(1.4.2)](#fs.op.is.empty-1.4.2)

      For the signature with argument ec,
 return false if an error occurred[.](#fs.op.is.empty-1.4.2.sentence-1)

  * [(1.4.3)](#fs.op.is.empty-1.4.3)

      Otherwise, return sz == 0[.](#fs.op.is.empty-1.4.3.sentence-1)

[2](#fs.op.is.empty-2)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.is.empty-2.sentence-1)

#### [31.12.13.21](#fs.op.is.fifo) Is fifo [[fs.op.is.fifo]](fs.op.is.fifo)

[ð](#lib:is_fifo)

`bool filesystem::is_fifo(file_status s) noexcept;
`

[1](#fs.op.is.fifo-1)

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

*Returns*: s.type() == file_type​::​fifo[.](#fs.op.is.fifo-1.sentence-1)

[ð](#lib:is_fifo_)

`bool filesystem::is_fifo(const path& p);
bool filesystem::is_fifo(const path& p, error_code& ec) noexcept;
`

[2](#fs.op.is.fifo-2)

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

*Returns*: is_fifo(status(p)) or is_fifo(status(p, ec)), respectively[.](#fs.op.is.fifo-2.sentence-1)

The signature with argument ec returns false if an error occurs[.](#fs.op.is.fifo-2.sentence-2)

[3](#fs.op.is.fifo-3)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.is.fifo-3.sentence-1)

#### [31.12.13.22](#fs.op.is.other) Is other [[fs.op.is.other]](fs.op.is.other)

[ð](#lib:is_other)

`bool filesystem::is_other(file_status s) noexcept;
`

[1](#fs.op.is.other-1)

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

*Returns*: exists(s) && !is_regular_file(s) && !is_directory(s) && !is_symlink(s)[.](#fs.op.is.other-1.sentence-1)

[ð](#lib:is_other_)

`bool filesystem::is_other(const path& p);
bool filesystem::is_other(const path& p, error_code& ec) noexcept;
`

[2](#fs.op.is.other-2)

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

*Returns*: is_other(status(p)) or is_other(status(p, ec)),
 respectively[.](#fs.op.is.other-2.sentence-1)

The signature with argument ec returns false if an error occurs[.](#fs.op.is.other-2.sentence-2)

[3](#fs.op.is.other-3)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.is.other-3.sentence-1)

#### [31.12.13.23](#fs.op.is.regular.file) Is regular file [[fs.op.is.regular.file]](fs.op.is.regular.file)

[ð](#lib:is_regular_file)

`bool filesystem::is_regular_file(file_status s) noexcept;
`

[1](#fs.op.is.regular.file-1)

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

*Returns*: s.type() == file_type​::​regular[.](#fs.op.is.regular.file-1.sentence-1)

[ð](#lib:is_regular_file_)

`bool filesystem::is_regular_file(const path& p);
`

[2](#fs.op.is.regular.file-2)

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

*Returns*: is_regular_file(status(p))[.](#fs.op.is.regular.file-2.sentence-1)

[3](#fs.op.is.regular.file-3)

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

*Throws*: filesystem_error if status(p) would throw filesystem_error[.](#fs.op.is.regular.file-3.sentence-1)

[ð](#lib:is_regular_file__)

`bool filesystem::is_regular_file(const path& p, error_code& ec) noexcept;
`

[4](#fs.op.is.regular.file-4)

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

*Effects*: Sets ec as if by status(p, ec)[.](#fs.op.is.regular.file-4.sentence-1)

[*Note [1](#fs.op.is.regular.file-note-1)*:

file_type​::​none, file_type​::​not_found and file_type​::​unknown cases set ec to error values[.](#fs.op.is.regular.file-4.sentence-2)

To distinguish between cases, call the status function directly[.](#fs.op.is.regular.file-4.sentence-3)

â *end note*]

[5](#fs.op.is.regular.file-5)

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

*Returns*: is_regular_file(status(p, ec))[.](#fs.op.is.regular.file-5.sentence-1)

Returns false if an error occurs[.](#fs.op.is.regular.file-5.sentence-2)

#### [31.12.13.24](#fs.op.is.socket) Is socket [[fs.op.is.socket]](fs.op.is.socket)

[ð](#lib:is_socket)

`bool filesystem::is_socket(file_status s) noexcept;
`

[1](#fs.op.is.socket-1)

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

*Returns*: s.type() == file_type​::​socket[.](#fs.op.is.socket-1.sentence-1)

[ð](#lib:is_socket_)

`bool filesystem::is_socket(const path& p);
bool filesystem::is_socket(const path& p, error_code& ec) noexcept;
`

[2](#fs.op.is.socket-2)

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

*Returns*: is_socket(status(p)) or is_socket(status(p, ec)), respectively[.](#fs.op.is.socket-2.sentence-1)

The signature with argument ec returns false if an error occurs[.](#fs.op.is.socket-2.sentence-2)

[3](#fs.op.is.socket-3)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.is.socket-3.sentence-1)

#### [31.12.13.25](#fs.op.is.symlink) Is symlink [[fs.op.is.symlink]](fs.op.is.symlink)

[ð](#lib:is_symlink)

`bool filesystem::is_symlink(file_status s) noexcept;
`

[1](#fs.op.is.symlink-1)

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

*Returns*: s.type() == file_type​::​symlink[.](#fs.op.is.symlink-1.sentence-1)

[ð](#lib:is_symlink_)

`bool filesystem::is_symlink(const path& p);
bool filesystem::is_symlink(const path& p, error_code& ec) noexcept;
`

[2](#fs.op.is.symlink-2)

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

*Returns*: is_symlink(symlink_status(p)) or is_symlink(symlink_status(p, ec)),
 respectively[.](#fs.op.is.symlink-2.sentence-1)

The signature with argument ec returns false if an error occurs[.](#fs.op.is.symlink-2.sentence-2)

[3](#fs.op.is.symlink-3)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.is.symlink-3.sentence-1)

#### [31.12.13.26](#fs.op.last.write.time) Last write time [[fs.op.last.write.time]](fs.op.last.write.time)

[ð](#lib:last_write_time)

`file_time_type filesystem::last_write_time(const path& p);
file_time_type filesystem::last_write_time(const path& p, error_code& ec) noexcept;
`

[1](#fs.op.last.write.time-1)

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

*Returns*: The time of last data modification of p,
 determined as if by the value of the POSIX stat class member st_mtime obtained as if by POSIX stat[.](#fs.op.last.write.time-1.sentence-1)

The signature with argument ec returns file_time_type​::​min() if an error occurs[.](#fs.op.last.write.time-1.sentence-2)

[2](#fs.op.last.write.time-2)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.last.write.time-2.sentence-1)

[ð](#lib:last_write_time_)

`void filesystem::last_write_time(const path& p, file_time_type new_time);
void filesystem::last_write_time(const path& p, file_time_type new_time,
                     error_code& ec) noexcept;
`

[3](#fs.op.last.write.time-3)

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

*Effects*: Sets the time of last data modification of the file
 resolved to by p to new_time, as if by POSIX [futimens](http://pubs.opengroup.org/onlinepubs/9699919799/functions/futimens.html)[.](#fs.op.last.write.time-3.sentence-1)

[4](#fs.op.last.write.time-4)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.last.write.time-4.sentence-1)

[5](#fs.op.last.write.time-5)

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

[*Note [1](#fs.op.last.write.time-note-1)*:

A postcondition of last_write_time(p) == new_time is not specified
because it does not necessarily hold for file systems with coarse time granularity[.](#fs.op.last.write.time-5.sentence-1)

â *end note*]

#### [31.12.13.27](#fs.op.permissions) Permissions [[fs.op.permissions]](fs.op.permissions)

[ð](#lib:permissions)

`void filesystem::permissions(const path& p, perms prms, perm_options opts=perm_options::replace);
void filesystem::permissions(const path& p, perms prms, error_code& ec) noexcept;
void filesystem::permissions(const path& p, perms prms, perm_options opts, error_code& ec);
`

[1](#fs.op.permissions-1)

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

*Preconditions*: Exactly one of the perm_options constantsreplace, add, or remove is present in opts[.](#fs.op.permissions-1.sentence-1)

[2](#fs.op.permissions-2)

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

*Effects*: Applies the action specified by opts to the file p resolves to,
or to file p itself if p is a symbolic link
and perm_options​::​nofollow is set in opts[.](#fs.op.permissions-2.sentence-1)

The action is applied as if by POSIX fchmodat[.](#fs.op.permissions-2.sentence-2)

[3](#fs.op.permissions-3)

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

[*Note [1](#fs.op.permissions-note-1)*:

Conceptually permissions are viewed as bits, but the actual
implementation can use some other mechanism[.](#fs.op.permissions-3.sentence-1)

â *end note*]

[4](#fs.op.permissions-4)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.permissions-4.sentence-1)

[5](#fs.op.permissions-5)

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

*Remarks*: The second signature behaves as if it had an additional parameterperm_options opts with an argument of perm_options​::​replace[.](#fs.op.permissions-5.sentence-1)

#### [31.12.13.28](#fs.op.proximate) Proximate [[fs.op.proximate]](fs.op.proximate)

[ð](#lib:proximate)

`path filesystem::proximate(const path& p, error_code& ec);
`

[1](#fs.op.proximate-1)

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

*Returns*: proximate(p, current_path(), ec)[.](#fs.op.proximate-1.sentence-1)

[2](#fs.op.proximate-2)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.proximate-2.sentence-1)

[ð](#lib:proximate_)

`path filesystem::proximate(const path& p, const path& base = current_path());
path filesystem::proximate(const path& p, const path& base, error_code& ec);
`

[3](#fs.op.proximate-3)

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

*Returns*: For the first form:weakly_canonical(p).lexically_proximate(weakly_canonical(base));

For the second form:weakly_canonical(p, ec).lexically_proximate(weakly_canonical(base, ec)); or path() at the first error occurrence, if any[.](#fs.op.proximate-3.sentence-2)

[4](#fs.op.proximate-4)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.proximate-4.sentence-1)

#### [31.12.13.29](#fs.op.read.symlink) Read symlink [[fs.op.read.symlink]](fs.op.read.symlink)

[ð](#lib:read_symlink)

`path filesystem::read_symlink(const path& p);
path filesystem::read_symlink(const path& p, error_code& ec);
`

[1](#fs.op.read.symlink-1)

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

*Returns*: If p resolves to a symbolic
 link, a path object containing the contents of that symbolic
 link[.](#fs.op.read.symlink-1.sentence-1)

The signature with argument ec returns path() if an error occurs[.](#fs.op.read.symlink-1.sentence-2)

[2](#fs.op.read.symlink-2)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.read.symlink-2.sentence-1)

[*Note [1](#fs.op.read.symlink-note-1)*:

It is an error if p does not
 resolve to a symbolic link[.](#fs.op.read.symlink-2.sentence-2)

â *end note*]

#### [31.12.13.30](#fs.op.relative) Relative [[fs.op.relative]](fs.op.relative)

[ð](#lib:relative)

`path filesystem::relative(const path& p, error_code& ec);
`

[1](#fs.op.relative-1)

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

*Returns*: relative(p, current_path(), ec)[.](#fs.op.relative-1.sentence-1)

[2](#fs.op.relative-2)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.relative-2.sentence-1)

[ð](#lib:relative_)

`path filesystem::relative(const path& p, const path& base = current_path());
path filesystem::relative(const path& p, const path& base, error_code& ec);
`

[3](#fs.op.relative-3)

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

*Returns*: For the first form:weakly_canonical(p).lexically_relative(weakly_canonical(base));

For the second form:weakly_canonical(p, ec).lexically_relative(weakly_canonical(base, ec)); or path() at the first error occurrence, if any[.](#fs.op.relative-3.sentence-2)

[4](#fs.op.relative-4)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.relative-4.sentence-1)

#### [31.12.13.31](#fs.op.remove) Remove [[fs.op.remove]](fs.op.remove)

[ð](#lib:remove,path)

`bool filesystem::remove(const path& p);
bool filesystem::remove(const path& p, error_code& ec) noexcept;
`

[1](#fs.op.remove-1)

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

*Effects*: If exists(symlink_status(p, ec)), the file p is
 removed as if by POSIX remove[.](#fs.op.remove-1.sentence-1)

[*Note [1](#fs.op.remove-note-1)*:

A symbolic link is itself removed, rather than the file it
 resolves to[.](#fs.op.remove-1.sentence-2)

â *end note*]

[2](#fs.op.remove-2)

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

*Postconditions*: exists(symlink_status(p)) is false[.](#fs.op.remove-2.sentence-1)

[3](#fs.op.remove-3)

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

*Returns*: true if a file p has been removed and false otherwise[.](#fs.op.remove-3.sentence-1)

[*Note [2](#fs.op.remove-note-2)*:

Absence of a file p is not an error[.](#fs.op.remove-3.sentence-2)

â *end note*]

[4](#fs.op.remove-4)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.remove-4.sentence-1)

#### [31.12.13.32](#fs.op.remove.all) Remove all [[fs.op.remove.all]](fs.op.remove.all)

[ð](#lib:remove_all)

`uintmax_t filesystem::remove_all(const path& p);
uintmax_t filesystem::remove_all(const path& p, error_code& ec);
`

[1](#fs.op.remove.all-1)

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

*Effects*: Recursively deletes the contents of p if it exists,
 then deletes file p itself, as if by POSIX remove[.](#fs.op.remove.all-1.sentence-1)

[*Note [1](#fs.op.remove.all-note-1)*:

A symbolic link is itself removed, rather than the file it
 resolves to[.](#fs.op.remove.all-1.sentence-2)

â *end note*]

[2](#fs.op.remove.all-2)

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

*Postconditions*: exists(symlink_status(p)) is false[.](#fs.op.remove.all-2.sentence-1)

[3](#fs.op.remove.all-3)

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

*Returns*: The number of files removed[.](#fs.op.remove.all-3.sentence-1)

The signature with argument ec returns static_cast< uintmax_t>(-1) if an error
 occurs[.](#fs.op.remove.all-3.sentence-2)

[4](#fs.op.remove.all-4)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.remove.all-4.sentence-1)

#### [31.12.13.33](#fs.op.rename) Rename [[fs.op.rename]](fs.op.rename)

[ð](#lib:rename)

`void filesystem::rename(const path& old_p, const path& new_p);
void filesystem::rename(const path& old_p, const path& new_p, error_code& ec) noexcept;
`

[1](#fs.op.rename-1)

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

*Effects*: Renames old_p to new_p, as if by
 POSIX rename[.](#fs.op.rename-1.sentence-1)

[*Note [1](#fs.op.rename-note-1)*: 

- [(1.1)](#fs.op.rename-1.1)

  If old_p and new_p resolve to the same existing file,
 no action is taken[.](#fs.op.rename-1.1.sentence-1)

- [(1.2)](#fs.op.rename-1.2)

  Otherwise, the rename can include the following effects:
  * [(1.2.1)](#fs.op.rename-1.2.1)

if new_p resolves to an existing non-directory file, new_p is removed; otherwise,

  * [(1.2.2)](#fs.op.rename-1.2.2)

if new_p resolves to an existing directory, new_p is removed if empty on POSIX compliant operating systems
 but might be an error on other operating systems[.](#fs.op.rename-1.2.sentence-1)

A symbolic link is itself renamed, rather than the file it resolves to[.](#fs.op.rename-1.sentence-2)

â *end note*]

[2](#fs.op.rename-2)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.rename-2.sentence-1)

#### [31.12.13.34](#fs.op.resize.file) Resize file [[fs.op.resize.file]](fs.op.resize.file)

[ð](#lib:resize_file)

`void filesystem::resize_file(const path& p, uintmax_t new_size);
void filesystem::resize_file(const path& p, uintmax_t new_size, error_code& ec) noexcept;
`

[1](#fs.op.resize.file-1)

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

*Effects*: Causes the size that would be returned by file_size(p) to be
equal to new_size, as if by POSIX truncate[.](#fs.op.resize.file-1.sentence-1)

[2](#fs.op.resize.file-2)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.resize.file-2.sentence-1)

#### [31.12.13.35](#fs.op.space) Space [[fs.op.space]](fs.op.space)

[ð](#lib:space)

`space_info filesystem::space(const path& p);
space_info filesystem::space(const path& p, error_code& ec) noexcept;
`

[1](#fs.op.space-1)

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

*Returns*: An object of type space_info[.](#fs.op.space-1.sentence-1)

The value of the space_info object is determined as if by using POSIX statvfs to obtain a POSIX struct statvfs,
 and then multiplying its f_blocks, f_bfree,
 and f_bavail members by its f_frsize member,
 and assigning the results to the capacity, free,
 and available members respectively[.](#fs.op.space-1.sentence-2)

Any members for which the
 value cannot be determined shall be set to static_cast<uintmax_t>(-1)[.](#fs.op.space-1.sentence-3)

For the signature with argument ec, all members are set to static_cast<uintmax_t>(-1) if an error occurs[.](#fs.op.space-1.sentence-4)

[2](#fs.op.space-2)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.space-2.sentence-1)

[3](#fs.op.space-3)

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

*Remarks*: The value of member space_info​::​available is operating system dependent[.](#fs.op.space-3.sentence-1)

[*Note [1](#fs.op.space-note-1)*:

available might be
 less than free[.](#fs.op.space-3.sentence-2)

â *end note*]

#### [31.12.13.36](#fs.op.status) Status [[fs.op.status]](fs.op.status)

[ð](#lib:status)

`file_status filesystem::status(const path& p);
`

[1](#fs.op.status-1)

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

*Effects*: As if by:error_code ec;
file_status result = status(p, ec);if (result.type() == file_type::none)throw filesystem_error(*implementation-supplied-message*, p, ec);return result;

[2](#fs.op.status-2)

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

*Returns*: See above[.](#fs.op.status-2.sentence-1)

[3](#fs.op.status-3)

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

*Throws*: filesystem_error[.](#fs.op.status-3.sentence-1)

[*Note [1](#fs.op.status-note-1)*:

result values of file_status(file_type​::​not_found) and file_status(file_type​::​unknown) are not considered failures and do not
 cause an exception to be thrown[.](#fs.op.status-3.sentence-2)

â *end note*]

[ð](#lib:status_)

`file_status filesystem::status(const path& p, error_code& ec) noexcept;
`

[4](#fs.op.status-4)

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

*Effects*: If possible, determines the attributes
 of the file p resolves to, as if by using POSIX stat to obtain a POSIX struct stat[.](#fs.op.status-4.sentence-1)

If, during attribute determination, the underlying file system API reports
 an error, sets ec to indicate the specific error reported[.](#fs.op.status-4.sentence-2)

Otherwise, ec.clear()[.](#fs.op.status-4.sentence-3)

[*Note [2](#fs.op.status-note-2)*:

This allows users to inspect the specifics of underlying
 API errors even when the value returned by status is not file_status(file_type​::​none)[.](#fs.op.status-4.sentence-4)

â *end note*]

[5](#fs.op.status-5)

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

Let prms denote the result of (m & perms​::​mask),
where m is determined as if by converting the st_mode member
of the obtained struct stat to the type perms[.](#fs.op.status-5.sentence-1)

[6](#fs.op.status-6)

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

*Returns*: 

- [(6.1)](#fs.op.status-6.1)

  If ec != error_code():
  * [(6.1.1)](#fs.op.status-6.1.1)

      If the specific error indicates that p cannot be resolved
 because some element of the path does not exist, returns file_status(file_type​::​not_found)[.](#fs.op.status-6.1.1.sentence-1)

  * [(6.1.2)](#fs.op.status-6.1.2)

      Otherwise, if the specific error indicates that p can be resolved
 but the attributes cannot be determined, returns file_status(file_type​::​unknown)[.](#fs.op.status-6.1.2.sentence-1)

  * [(6.1.3)](#fs.op.status-6.1.3)

      Otherwise, returns file_status(file_type​::​none)[.](#fs.op.status-6.1.3.sentence-1)

  [*Note [3](#fs.op.status-note-3)*:
  These semantics distinguish between p being known not to exist, p existing but not being able to determine its attributes,
 and there being an error that prevents even knowing if p exists[.](#fs.op.status-6.1.sentence-2)
  These
 distinctions are important to some use cases[.](#fs.op.status-6.1.sentence-3)
 â *end note*]

- [(6.2)](#fs.op.status-6.2)

  Otherwise,
  * [(6.2.1)](#fs.op.status-6.2.1)

      If the attributes indicate a regular file, as if by POSIX S_ISREG,
 returns file_status(file_type​::​regular, prms)[.](#fs.op.status-6.2.1.sentence-1)
      [*Note [4](#fs.op.status-note-4)*:
      file_type​::​regular implies appropriate [<fstream>](fstream.syn#header:%3cfstream%3e "31.10.1 Header <fstream> synopsis [fstream.syn]") operations
 would succeed, assuming no hardware, permission, access, or file system
 race errors[.](#fs.op.status-6.2.1.sentence-2)
      Lack of file_type​::​regular does not necessarily imply [<fstream>](fstream.syn#header:%3cfstream%3e "31.10.1 Header <fstream> synopsis [fstream.syn]") operations would fail on a directory[.](#fs.op.status-6.2.1.sentence-3)
 â *end note*]

  * [(6.2.2)](#fs.op.status-6.2.2)

      Otherwise, if the attributes indicate a directory, as if by POSIX S_ISDIR, returns file_status(file_type​::​directory, prms)[.](#fs.op.status-6.2.2.sentence-1)
      [*Note [5](#fs.op.status-note-5)*:
      file_type​::​directory implies that calling directory_iterator(p) would succeed[.](#fs.op.status-6.2.2.sentence-2)
 â *end note*]

  * [(6.2.3)](#fs.op.status-6.2.3)

      Otherwise, if the attributes indicate a block special file, as if by
 POSIX S_ISBLK, returns file_status(file_type​::​block, prms)[.](#fs.op.status-6.2.3.sentence-1)

  * [(6.2.4)](#fs.op.status-6.2.4)

      Otherwise, if the attributes indicate a character special file, as if
 by POSIX S_ISCHR, returns file_status(file_type​::​character, prms)[.](#fs.op.status-6.2.4.sentence-1)

  * [(6.2.5)](#fs.op.status-6.2.5)

      Otherwise, if the attributes indicate a fifo or pipe file, as if by
 POSIX S_ISFIFO, returns file_status(file_type​::​fifo, prms)[.](#fs.op.status-6.2.5.sentence-1)

  * [(6.2.6)](#fs.op.status-6.2.6)

      Otherwise, if the attributes indicate a socket, as if by POSIX S_ISSOCK, returns file_status(file_type​::​socket, prms)[.](#fs.op.status-6.2.6.sentence-1)

  * [(6.2.7)](#fs.op.status-6.2.7)

      Otherwise, if the attributes indicate an implementation-defined
 file type ([[fs.enum.file.type]](#fs.enum.file.type "31.12.8.2 Enum class file_­type")),
 returns file_status(file_type​::​*A*, prms),
 where *A* is the constant for the implementation-defined file type[.](#fs.op.status-6.2.7.sentence-1)

  * [(6.2.8)](#fs.op.status-6.2.8)

      Otherwise, returns file_status(file_type​::​unknown, prms)[.](#fs.op.status-6.2.8.sentence-1)

[7](#fs.op.status-7)

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

*Remarks*: If a symbolic link is encountered during pathname resolution,
 pathname resolution continues using the contents of the symbolic link[.](#fs.op.status-7.sentence-1)

#### [31.12.13.37](#fs.op.status.known) Status known [[fs.op.status.known]](fs.op.status.known)

[ð](#lib:status_known)

`bool filesystem::status_known(file_status s) noexcept;
`

[1](#fs.op.status.known-1)

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

*Returns*: s.type() != file_type​::​none[.](#fs.op.status.known-1.sentence-1)

#### [31.12.13.38](#fs.op.symlink.status) Symlink status [[fs.op.symlink.status]](fs.op.symlink.status)

[ð](#lib:symlink_status)

`file_status filesystem::symlink_status(const path& p);
file_status filesystem::symlink_status(const path& p, error_code& ec) noexcept;
`

[1](#fs.op.symlink.status-1)

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

*Effects*: Same as status, above,
 except that the attributes
 of p are determined as if by using POSIX lstat to obtain a POSIX struct stat[.](#fs.op.symlink.status-1.sentence-1)

[2](#fs.op.symlink.status-2)

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

Let prms denote the result of (m & perms​::​mask),
where m is determined as if by converting the st_mode member
of the obtained struct stat to the type perms[.](#fs.op.symlink.status-2.sentence-1)

[3](#fs.op.symlink.status-3)

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

*Returns*: Same as status, above, except
 that if the attributes indicate a symbolic link, as if by POSIX S_ISLNK,
 returns file_status(file_type​::​symlink, prms)[.](#fs.op.symlink.status-3.sentence-1)

The signature with argument ec returns file_status(file_type​::​none) if an error occurs[.](#fs.op.symlink.status-3.sentence-2)

[4](#fs.op.symlink.status-4)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.symlink.status-4.sentence-1)

[5](#fs.op.symlink.status-5)

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

*Remarks*: Pathname resolution terminates if p names a symbolic link[.](#fs.op.symlink.status-5.sentence-1)

#### [31.12.13.39](#fs.op.temp.dir.path) Temporary directory path [[fs.op.temp.dir.path]](fs.op.temp.dir.path)

[ð](#lib:temp_directory_path)

`path filesystem::temp_directory_path();
path filesystem::temp_directory_path(error_code& ec);
`

[1](#fs.op.temp.dir.path-1)

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

Let p be an unspecified directory path suitable for temporary files[.](#fs.op.temp.dir.path-1.sentence-1)

[2](#fs.op.temp.dir.path-2)

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

*Effects*: If exists(p) is false or is_directory(p) is false, an error is reported ([[fs.err.report]](#fs.err.report "31.12.5 Error reporting"))[.](#fs.op.temp.dir.path-2.sentence-1)

[3](#fs.op.temp.dir.path-3)

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

*Returns*: The path p[.](#fs.op.temp.dir.path-3.sentence-1)

The signature with argument ec returns path() if an
 error occurs[.](#fs.op.temp.dir.path-3.sentence-2)

[4](#fs.op.temp.dir.path-4)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.temp.dir.path-4.sentence-1)

[5](#fs.op.temp.dir.path-5)

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

[*Example [1](#fs.op.temp.dir.path-example-1)*:

For POSIX-based operating systems, an implementation might
 return the path
 supplied by the first environment variable found in the list TMPDIR, TMP, TEMP, TEMPDIR,
 or if none of these are found, "/tmp"[.](#fs.op.temp.dir.path-5.sentence-1)

For Windows-based operating systems, an implementation might return the path
 reported by the Windows GetTempPath API function[.](#fs.op.temp.dir.path-5.sentence-2)

â *end example*]

#### [31.12.13.40](#fs.op.weakly.canonical) Weakly canonical [[fs.op.weakly.canonical]](fs.op.weakly.canonical)

[ð](#lib:weakly_canonical)

`path filesystem::weakly_canonical(const path& p);
path filesystem::weakly_canonical(const path& p, error_code& ec);
`

[1](#fs.op.weakly.canonical-1)

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

*Effects*: Using status(p) or status(p, ec), respectively,
 to determine existence,
 return a path composed by operator/= from the result of calling canonical with a path argument composed of
 the leading elements of p that exist, if any, followed by
 the elements of p that do not exist, if any[.](#fs.op.weakly.canonical-1.sentence-1)

For the first form, canonical is called without an error_code argument[.](#fs.op.weakly.canonical-1.sentence-2)

For the second form, canonical is called
 with ec as an error_code argument, and path() is returned at the first error occurrence, if any[.](#fs.op.weakly.canonical-1.sentence-3)

[2](#fs.op.weakly.canonical-2)

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

*Postconditions*: The returned path is in normal form ([[fs.path.generic]](#fs.path.generic "31.12.6.2 Generic pathname format"))[.](#fs.op.weakly.canonical-2.sentence-1)

[3](#fs.op.weakly.canonical-3)

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

*Returns*: p with symlinks resolved and
 the result normalized ([[fs.path.generic]](#fs.path.generic "31.12.6.2 Generic pathname format"))[.](#fs.op.weakly.canonical-3.sentence-1)

[4](#fs.op.weakly.canonical-4)

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

*Throws*: As specified in [[fs.err.report]](#fs.err.report "31.12.5 Error reporting")[.](#fs.op.weakly.canonical-4.sentence-1)
