31 Input/output library [input.output]

31.12 File systems [filesystems]

31.12.1 General [fs.general]

Subclause [filesystems] describes operations on file systems and their components, such as paths, regular files, and directories.
A file system is a collection of files and their attributes.
A file is an object within a file system that holds user or system data.
Files can be written to, or read from, or both.
A file has certain attributes, including type.
File types include regular files and directories.
Other types of files, such as symbolic links, may be supported by the implementation.
A directory 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.
The parent directory 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]) in the given directory.
The parent directory of other types of files is a directory containing a directory entry for the file under discussion.
A link is an object that associates a filename with a file.
Several links can associate names with the same file.
A hard link is a link to an existing file.
Some file systems support multiple hard links to a file.
If the last hard link to a file is removed, the file itself is removed.
[Note 1: 
A hard link can be thought of as a shared-ownership smart pointer to a file.
— end note]
A symbolic link is a type of file with the property that when the file is encountered during pathname resolution ([fs.class.path]), a string stored by the file is used to modify the pathname resolution.
[Note 2: 
Symbolic links are often called symlinks.
A symbolic link can be thought of as a raw pointer to a file.
If the file pointed to does not exist, the symbolic link is said to be a “dangling” symbolic link.
— end note]

31.12.2 Conformance [fs.conformance]

31.12.2.1 General [fs.conformance.general]

Conformance is specified in terms of behavior.
Ideal behavior is not always implementable, so the conformance subclauses take that into account.

31.12.2.2 POSIX conformance [fs.conform.9945]

Some behavior is specified by reference to POSIX.
How such behavior is actually implemented is unspecified.
[Note 1: 
This constitutes an “as if” rule allowing implementations to call native operating system or other APIs.
— end note]
Implementations should provide such behavior as it is defined by POSIX.
Implementations shall document any behavior that differs from the behavior defined by POSIX.
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.
If an implementation cannot provide any reasonable behavior, the implementation shall report an error as specified in [fs.err.report].
[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.
— end note]
Implementations are not required to provide behavior that is not supported by a particular file system.
[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.
— end example]

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

Behavior that is specified as being operating system dependent is dependent upon the behavior and characteristics of an operating system.
The operating system an implementation is dependent upon is implementation-defined.
It is permissible for an implementation to be dependent upon an operating system emulator rather than the actual underlying operating system.

31.12.2.4 File system race behavior [fs.race.behavior]

A file system race is the condition that occurs when multiple threads, processes, or computers interleave access and modification of the same object within a file system.
Behavior is undefined if calls to functions provided by subclause [filesystems] introduce a file system race.
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.
[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.
— end note]

31.12.3 Requirements [fs.req]

Throughout subclause [filesystems], char, wchar_t, char8_t, char16_t, and char32_t are collectively called encoded character types.
Functions with template parameters named EcharT shall not participate in overload resolution unless EcharT is one of the encoded character types.
Template parameters named InputIterator shall meet the Cpp17InputIterator requirements ([input.iterators]) and shall have a value type that is one of the encoded character types.
[Note 1: 
Use of an encoded character type implies an associated character set and encoding.
Since signed char and unsigned char have no implied character set and encoding, they are not included as permitted types.
— end note]
Template parameters named Allocator shall meet the Cpp17Allocator requirements ([allocator.requirements.general]).

31.12.4 Header <filesystem> synopsis [fs.filesystem.syn]

#include <compare> // see [compare.syn] namespace std::filesystem { // [fs.class.path], paths class path; // [fs.path.nonmember], path non-member functions void swap(path& lhs, path& rhs) noexcept; size_t hash_value(const path& p) noexcept; // [fs.class.filesystem.error], filesystem errors class filesystem_error; // [fs.class.directory.entry], directory entries class directory_entry; // [fs.class.directory.iterator], directory iterators class directory_iterator; // [fs.dir.itr.nonmembers], range access for directory iterators directory_iterator begin(directory_iterator iter) noexcept; directory_iterator end(directory_iterator) noexcept; // [fs.class.rec.dir.itr], recursive directory iterators class recursive_directory_iterator; // [fs.rec.dir.itr.nonmembers], 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], file status class 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], enumerations enum 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], 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); } // [fs.path.hash], hash support namespace std { template<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; }
Implementations should ensure that the resolution and range of file_time_type reflect the operating system dependent resolution and range of file time values.

31.12.5 Error reporting [fs.err.report]

Filesystem library functions often provide two overloads, one that throws an exception to report file system errors, and another that sets an error_code.
[Note 1: 
This supports two common use cases:
  • Uses where file system errors are truly exceptional and indicate a serious failure.
    Throwing an exception is an appropriate response.
  • Uses where file system errors are routine and do not necessarily represent failure.
    Returning an error code is the most appropriate response.
    This allows application specific error handling, including simply ignoring the error.
— end note]
Functions not having an argument of type error_code& handle errors as follows, unless otherwise specified:
  • 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 type filesystem_error shall be thrown.
    For functions with a single path argument, that argument shall be passed to the filesystem_error constructor with a single path argument.
    For functions with two path arguments, the first of these arguments shall be passed to the filesystem_error constructor as the path1 argument, and the second shall be passed as the path2 argument.
    The filesystem_error constructor's error_code argument is set as appropriate for the specific operating system dependent error.
  • Failure to allocate storage is reported by throwing an exception as described in [res.on.exception.handling].
  • Destructors throw nothing.
Functions having an argument of type error_code& handle errors as follows, unless otherwise specified:
  • 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.
    Otherwise, clear() is called on the error_code& argument.

31.12.6 Class path [fs.class.path]

31.12.6.1 General [fs.class.path.general]

An object of class path represents a path and contains a pathname.
Such an object is concerned only with the lexical and syntactic aspects of a path.
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.
[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.
— end note]
A path is a sequence of elements that identify the location of a file within a filesystem.
The elements are the root-name, root-directory, and an optional sequence of filenames ([fs.path.generic]).
The maximum number of elements in the sequence is operating system dependent ([fs.conform.os]).
An absolute path is a path that unambiguously identifies the location of a file without reference to an additional starting location.
The elements of a path that determine if it is absolute are operating system dependent.
A relative path 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.
The elements of a path that determine if it is relative are operating system dependent.
[Note 2: 
Pathnames “.” and “..” are relative paths.
— end note]
A pathname is a character string that represents the name of a path.
Pathnames are formatted according to the generic pathname format grammar ([fs.path.generic]) or according to an operating system dependent native pathname format accepted by the host operating system.
Pathname resolution is the operating system dependent mechanism for resolving a pathname to a particular file in a file hierarchy.
There may be multiple pathnames that resolve to the same file.
[Example 1: 
POSIX specifies the mechanism in section 4.12, Pathname resolution.
— 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], enumeration format enum format; // [fs.path.construct], 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], 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], 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], 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], modifiers void 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], non-member operators friend 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], native format observers const 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 string() const; std::wstring wstring() const; std::u8string u8string() const; std::u16string u16string() const; std::u32string u32string() const; // [fs.path.generic.obs], generic format observers template<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_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], compare int 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], 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], query [[nodiscard]] bool 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], generation path lexically_normal() const; path lexically_relative(const path& base) const; path lexically_proximate(const path& base) const; // [fs.path.itr], iterators class iterator; using const_iterator = iterator; iterator begin() const; iterator end() const; // [fs.path.io], path inserter and extractor template<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); }; }
value_type is a typedef for the operating system dependent encoded character type used to represent pathnames.
The value of the preferred_separator member is the operating system dependent preferred-separator character ([fs.path.generic]).
[Example 2: 
For POSIX-based operating systems, value_type is char and preferred_separator is the slash character ('/').
For Windows-based operating systems, value_type is wchar_t and preferred_separator is the backslash character (L'\\').
— end example]

31.12.6.2 Generic pathname format [fs.path.generic]

root-name:
operating system dependent sequences of characters
implementation-defined sequences of characters
filename:
non-empty sequence of characters other than directory-separator characters
preferred-separator:
operating system dependent directory separator character
A filename is the name of a file.
The dot and dot-dot filenames, consisting solely of one and two period characters respectively, have special meaning.
The following characteristics of filenames are operating system dependent:
  • The permitted characters.
    [Example 1: 
    Some operating systems prohibit the ASCII control characters (0x00 – 0x1F) in filenames.
    — end example]
    [Note 1: 
    Wider portability can be achieved by limiting filename 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]
  • The maximum permitted length.
  • Filenames that are not permitted.
  • Filenames that have special meaning.
  • Case awareness and sensitivity during path resolution.
  • Special rules that may apply to file types other than regular files, such as directories.
Except in a root-name, multiple successive directory-separator characters are considered to be the same as one directory-separator character.
The dot filename is treated as a reference to the current directory.
The dot-dot filename is treated as a reference to the parent directory.
What the dot-dot filename refers to relative to root-directory is implementation-defined.
Specific filenames may have special meanings for a particular operating system.
A root-name identifies the starting location for pathname resolution ([fs.class.path]).
If there are no operating system dependent root-names, at least one implementation-defined root-name is required.
[Note 2: 
Many operating systems define a name beginning with two directory-separator characters as a root-name that identifies network or other resource locations.
Some operating systems define a single letter followed by a colon as a drive specifier — a root-name identifying a specific device such as a disk drive.
— end note]
If a root-name is otherwise ambiguous, the possibility with the longest sequence of characters is chosen.
[Note 3: 
On a POSIX-like operating system, it is impossible to have a root-name and a relative-path without an intervening root-directory element.
— end note]
Normalization of a generic format pathname means:
1.
If the path is empty, stop.
2.
Replace each slash character in the root-name with a preferred-separator.
3.
[Note 4: 
The generic pathname grammar defines directory-separator as one or more slashes and preferred-separators.
— end note]
4.
Remove each dot filename and any immediately following directory-separator.
5.
As long as any appear, remove a non-dot-dot filename immediately followed by a directory-separator and a dot-dot filename, along with any immediately following directory-separator.
6.
If there is a root-directory, remove all dot-dot filenames and any directory-separators immediately following them.
[Note 5: 
These dot-dot filenames attempt to refer to nonexistent parent directories.
— end note]
7.
If the last filename is dot-dot, remove any trailing directory-separator.
8.
If the path is empty, add a dot.
The result of normalization is a path in normal form, which is said to be normalized.

31.12.6.3 Conversions [fs.path.cvt]

31.12.6.3.1 Argument format conversions [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:
  • The generic format is acceptable as a native path.
  • There is no need to distinguish between native format and generic format in function arguments.
  • Paths for regular files and paths for directories share the same syntax.
— end note]
Several functions are defined to accept detected-format arguments, which are character sequences.
A detected-format argument represents a path using either a pathname in the generic format ([fs.path.generic]) or a pathname in the native format ([fs.class.path]).
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.
[Note 2: 
Some operating systems have no unambiguous way to distinguish between native format and generic format arguments.
This is by design as it simplifies use for operating systems that do not require disambiguation.
An implementation for an operating system where disambiguation is required is permitted to distinguish between the formats.
— end note]
Pathnames are converted as needed between the generic and native formats in an operating-system-dependent manner.
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.
If g=G(n) for some n, then G(N(g))=g; if n=N(g) for some g, then N(G(n))=n.
[Note 3: 
Neither G nor N need be invertible.
— end note]
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, otherwise it shall be treated as a path to a regular file.
[Note 4: 
A path stores a native format pathname ([fs.path.native.obs]) and acts as if it also stores a generic format pathname, related as given below.
The implementation can generate the generic format pathname based on the native format pathname (and possibly other information) when requested.
— end note]
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).
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.
The value q converts to p (by G or N as appropriate) if any such value does so; q is otherwise unspecified.
[Note 5: 
If q is the result of converting any path at all, it is the result of converting p.
— end note]

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

The native encoding of an ordinary character string is the operating system dependent current encoding for pathnames ([fs.class.path]).
The native encoding for wide character strings is the implementation-defined execution wide-character set encoding ([character.seq]).
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 from path​::​value_type.
For the argument or return value, the method of conversion and the encoding to be converted to is determined by its value type:
  • char: The encoding is the native ordinary encoding.
    The method of conversion, if any, is operating system dependent.
    [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.
    For Windows-based operating systems, the native ordinary encoding is determined by calling a Windows API function.
    — end note]
    [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.
    Changing this behavior would be surprising and error-prone.
    — end note]
  • wchar_t: The encoding is the native wide encoding.
    The method of conversion is unspecified.
    [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.
    — end note]
  • char8_t: The encoding is UTF-8.
    The method of conversion is unspecified.
  • char16_t: The encoding is UTF-16.
    The method of conversion is unspecified.
  • char32_t: The encoding is UTF-32.
    The method of conversion is unspecified.
If the encoding being converted to has no representation for source characters, the resulting converted characters, if any, are unspecified.
Implementations should not modify member function arguments if already of type path​::​value_type.

31.12.6.4 Requirements [fs.path.req]

In addition to the requirements ([fs.req]), function template parameters named Source shall be one of:
  • basic_string<EcharT, traits, Allocator>.
    A function argument const Source& source shall have an effective range [source.begin(), source.end()).
  • basic_string_view<EcharT, traits>.
    A function argument const Source& source shall have an effective range [source.begin(), source.end()).
  • A type meeting the Cpp17InputIterator requirements that iterates over a NTCTS.
    The value type shall be an encoded character type.
    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().
  • A character array that after array-to-pointer decay results in a pointer to the start of a NTCTS.
    The value type shall be an encoded character type.
    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().
Functions taking template parameters named Source shall not participate in overload resolution unless Source denotes a type other than path, and either
  • Source is a specialization of basic_string or basic_string_view, or
  • the qualified-id iterator_traits<decay_t<Source>>​::​value_type is valid and denotes a possibly const encoded character type ([temp.deduct]).
[Note 1: 
See path conversions for how the value types above and their encodings convert to path​::​value_type and its encoding.
— end note]
Arguments of type Source shall not be null pointers.

31.12.6.5 Members [fs.path.member]

31.12.6.5.1 Constructors [fs.path.construct]

path() noexcept;
Postconditions: empty() == true.
path(const path& p); path(path&& p) noexcept;
Effects: Constructs an object of class path having the same pathname in the native and generic formats, respectively, as the original value of p.
In the second form, p is left in a valid but unspecified state.
path(string_type&& source, format fmt = auto_format);
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]), converting format if required ([fs.path.fmt.cvt]).
source is left in a valid but unspecified state.
template<class Source> path(const Source& source, format fmt = auto_format); template<class InputIterator> path(InputIterator first, InputIterator last, format fmt = auto_format);
Effects: Let s be the effective range of source ([fs.path.req]) or the range [first, last), with the encoding converted if required ([fs.path.cvt]).
Finds the detected-format of s ([fs.path.fmt.cvt]) and constructs an object of class path for which the pathname in that format is s.
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);
Mandates: The value type of Source and InputIterator is char.
Effects: Let s be the effective range of source or the range [first, last), after converting the encoding as follows:
  • If value_type is wchar_t, converts to the native wide encoding ([fs.path.type.cvt]) using the codecvt<wchar_t, char, mbstate_t> facet of loc.
  • Otherwise a conversion is performed using the codecvt<wchar_t, char, mbstate_t> facet of loc, and then a second conversion to the current ordinary encoding.
Finds the detected-format of s ([fs.path.fmt.cvt]) and constructs an object of class path for which the pathname in that format is s.
[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 using latin1_facet to convert ISO/IEC 8859-1 encoded latin1_string to a wide character string in the native wide encoding ([fs.path.type.cvt]).
The resulting wide string is then converted to an ordinary character pathname string in the current native ordinary encoding.
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.
For Windows-based operating systems, the path is constructed by using latin1_facet to convert ISO/IEC 8859-1 encoded latin1_string to a UTF-16 encoded wide character pathname string.
All of the characters in the ISO/IEC 8859-1 character set will be converted to their Unicode representation.
— end example]

31.12.6.5.2 Assignments [fs.path.assign]

path& operator=(const path& p);
Effects: If *this and p are the same object, has no effect.
Otherwise, sets both respective pathnames of *this to the respective pathnames of p.
Returns: *this.
path& operator=(path&& p) noexcept;
Effects: If *this and p are the same object, has no effect.
Otherwise, sets both respective pathnames of *this to the respective pathnames of p.
p is left in a valid but unspecified state.
[Note 1: 
A valid implementation is swap(p).
— end note]
Returns: *this.
path& operator=(string_type&& source); path& assign(string_type&& source);
Effects: Sets the pathname in the detected-format of source to the original value of source.
source is left in a valid but unspecified state.
Returns: *this.
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);
Effects: Let s be the effective range of source ([fs.path.req]) or the range [first, last), with the encoding converted if required ([fs.path.cvt]).
Finds the detected-format of s ([fs.path.fmt.cvt]) and sets the pathname in that format to s.
Returns: *this.

31.12.6.5.3 Appends [fs.path.append]

The append operations use operator/= to denote their semantic effect of appending preferred-separator when needed.
path& operator/=(const path& p);
Effects: If p.is_absolute() || (p.has_root_name() && p.root_name() != root_name()), then operator=(p).
Otherwise, modifies *this as if by these steps:
  • If p.has_root_directory(), then removes any root directory and relative path from the generic format pathname.
    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.
  • Then appends the native format pathname of p, omitting any root-name from its generic format pathname, to the native format pathname.
[Example 1: 
Even if //host is interpreted as a root-name, both of the paths path("//host")/"foo" and path("//host/")/"foo" equal "//host/foo" (although the former might use backslash as the preferred separator).
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]
Returns: *this.
template<class Source> path& operator/=(const Source& source); template<class Source> path& append(const Source& source);
Effects: Equivalent to: return operator/=(path(source));
template<class InputIterator> path& append(InputIterator first, InputIterator last);
Effects: Equivalent to: return operator/=(path(first, last));

31.12.6.5.4 Concatenation [fs.path.concat]

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);
Effects: Appends path(x).native() to the pathname in the native format.
[Note 1: 
This directly manipulates the value of native(), which is not necessarily portable between operating systems.
— end note]
Returns: *this.
path& operator+=(value_type x); template<class EcharT> path& operator+=(EcharT x);
Effects: Equivalent to: return *this += basic_string_view(&x, 1);
template<class InputIterator> path& concat(InputIterator first, InputIterator last);
Effects: Equivalent to: return *this += path(first, last);

31.12.6.5.5 Modifiers [fs.path.modifiers]

void clear() noexcept;
Postconditions: empty() == true.
path& make_preferred();
Effects: Each directory-separator of the pathname in the generic format is converted to preferred-separator.
Returns: *this.
[Example 1: path p("foo/bar"); std::cout << p << '\n'; p.make_preferred(); std::cout << p << '\n';
On an operating system where preferred-separator is a slash, the output is: "foo/bar" "foo/bar"
On an operating system where preferred-separator is a backslash, the output is: "foo/bar" "foo\bar"
— end example]
path& remove_filename();
Effects: Remove the generic format pathname of filename() from the generic format pathname.
Postconditions: !has_filename().
Returns: *this.
[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]
path& replace_filename(const path& replacement);
Effects: Equivalent to: remove_filename(); operator/=(replacement);
Returns: *this.
[Example 3: path("/foo").replace_filename("bar"); // yields "/bar" on POSIX path("/").replace_filename("bar"); // yields "/bar" on POSIX — end example]
path& replace_extension(const path& replacement = path());
Effects:
  • Any existing extension() ([fs.path.decompose]) is removed from the pathname in the generic format, then
  • 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
  • operator+=(replacement);.
Returns: *this.
void swap(path& rhs) noexcept;
Effects: Swaps the contents (in all formats) of the two paths.
Complexity: Constant time.

31.12.6.5.6 Native format observers [fs.path.native.obs]

The string returned by all native format observers is in the native pathname format ([fs.class.path]).
const string_type& native() const noexcept;
Returns: The pathname in the native format.
const value_type* c_str() const noexcept;
Effects: Equivalent to: return native().c_str();
operator string_type() const;
Returns: native().
template<class EcharT, class traits = char_traits<EcharT>, class Allocator = allocator<EcharT>> basic_string<EcharT, traits, Allocator> string(const Allocator& a = Allocator()) const;
Returns: native().
Remarks: All memory allocation, including for the return value, shall be performed by a.
Conversion, if any, is specified by [fs.path.cvt].
std::string string() const; std::wstring wstring() const; std::u8string u8string() const; std::u16string u16string() const; std::u32string u32string() const;
Returns: native().
Remarks: Conversion, if any, is performed as specified by [fs.path.cvt].

31.12.6.5.7 Generic format observers [fs.path.generic.obs]

Generic format observer functions return strings formatted according to the generic pathname format.
A single slash ('/') character is used as the directory-separator.
[Example 1: 
On an operating system that uses backslash as its preferred-separator, path("foo\\bar").generic_string() returns "foo/bar".
— end example]
template<class EcharT, class traits = char_traits<EcharT>, class Allocator = allocator<EcharT>> basic_string<EcharT, traits, Allocator> generic_string(const Allocator& a = Allocator()) const;
Returns: The pathname in the generic format.
Remarks: All memory allocation, including for the return value, shall be performed by a.
Conversion, if any, is specified by [fs.path.cvt].
std::string generic_string() const; std::wstring generic_wstring() const; std::u8string generic_u8string() const; std::u16string generic_u16string() const; std::u32string generic_u32string() const;
Returns: The pathname in the generic format.
Remarks: Conversion, if any, is specified by [fs.path.cvt].

31.12.6.5.8 Compare [fs.path.compare]

int compare(const path& p) const noexcept;
Returns:
  • Let rootNameComparison be the result of this->root_name().native().compare(p.root_name().native()).
    If rootNameComparison is not 0, rootNameComparison.
  • Otherwise, if !this->has_root_directory() and p.has_root_directory(), a value less than 0.
  • Otherwise, if this->has_root_directory() and !p.has_root_directory(), a value greater than 0.
  • 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.
  • 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.
  • Otherwise, 0.
int compare(const string_type& s) const; int compare(basic_string_view<value_type> s) const; int compare(const value_type* s) const;
Effects: Equivalent to: return compare(path(s));

31.12.6.5.9 Decomposition [fs.path.decompose]

path root_name() const;
Returns: root-name, if the pathname in the generic format includes root-name, otherwise path().
path root_directory() const;
Returns: root-directory, if the pathname in the generic format includes root-directory, otherwise path().
path root_path() const;
Returns: root_name() / root_directory().
path relative_path() const;
Returns: A path composed from the pathname in the generic format, if empty() is false, beginning with the first filename after root_path().
Otherwise, path().
path parent_path() const;
Returns: *this if has_relative_path() is false, otherwise a path whose generic format pathname is the longest prefix of the generic format pathname of *this that produces one fewer element in its iteration.
path filename() const;
Returns: relative_path().empty() ? path() : *--end().
[Example 1: path("/foo/bar.txt").filename(); // yields "bar.txt" path("/foo/bar").filename(); // yields "bar" path("/foo/bar/").filename(); // yields "" path("/").filename(); // yields "" path("//host").filename(); // yields "" path(".").filename(); // yields "." path("..").filename(); // yields ".." — end example]
path stem() const;
Returns: Let f be the generic format pathname of filename().
Returns a path whose pathname in the generic format is
  • f, if it contains no periods other than a leading period or consists solely of one or two periods;
  • otherwise, the prefix of f ending before its last period.
[Example 2: std::cout << path("/foo/bar.txt").stem(); // outputs "bar" path p = "foo.bar.baz.tar"; for (; !p.extension().empty(); p = p.stem()) std::cout << p.extension() << '\n'; // outputs: .tar // .baz // .bar — end example]
path extension() const;
Returns: A path whose pathname in the generic format is the suffix of filename() not included in stem().
[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]
[Note 1: 
The period is included in the return value so that it is possible to distinguish between no extension and an empty extension.
— end note]
[Note 2: 
On non-POSIX operating systems, for a path p, it is possible that p.stem() + p.extension() == p.filename() is false, even though the generic format pathnames are the same.
— end note]

31.12.6.5.10 Query [fs.path.query]

[[nodiscard]] bool empty() const noexcept;
Returns: true if the pathname in the generic format is empty, otherwise false.
bool has_root_path() const;
Returns: !root_path().empty().
bool has_root_name() const;
Returns: !root_name().empty().
bool has_root_directory() const;
Returns: !root_directory().empty().
bool has_relative_path() const;
Returns: !relative_path().empty().
bool has_parent_path() const;
Returns: !parent_path().empty().
bool has_filename() const;
Returns: !filename().empty().
bool has_stem() const;
Returns: !stem().empty().
bool has_extension() const;
Returns: !extension().empty().
bool is_absolute() const;
Returns: true if the pathname in the native format contains an absolute path ([fs.class.path]), otherwise false.
[Example 1: 
path("/").is_absolute() is true for POSIX-based operating systems, and false for Windows-based operating systems.
— end example]
bool is_relative() const;
Returns: !is_absolute().

31.12.6.5.11 Generation [fs.path.gen]

path lexically_normal() const;
Returns: A path whose pathname in the generic format is the normal form ([fs.path.generic]) of the pathname in the generic format of *this.
[Example 1: assert(path("foo/./bar/..").lexically_normal() == "foo/"); assert(path("foo/.///bar/../").lexically_normal() == "foo/");
The above assertions will succeed.
On Windows, the returned path's directory-separator characters will be backslashes rather than slashes, but that does not affect path equality.
— end example]
path lexically_relative(const path& base) const;
Effects: If:
  • root_name() != base.root_name() is true, or
  • is_absolute() != base.is_absolute() is true, or
  • !has_root_directory() && base.has_root_directory() is true, or
  • any filename in relative_path() or base.relative_path() can be interpreted as a root-name,
returns path().
[Note 1: 
On a POSIX implementation, no filename in a relative-path is acceptable as a root-name.
— 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,
  • if a == end() and b == base.end(), returns path("."); otherwise
  • let n be the number of filename elements in [b, base.end()) that are not dot or dot-dot or empty, minus the number that are dot-dot.
    If n<0, returns path(); otherwise
  • if n == 0 and (a == end() || a->empty()), returns path("."); otherwise
  • returns an object of class path that is default-constructed, followed by
    • application of operator/=(path("..")) n times, and then
    • application of operator/= for each element in [a, end()).
Returns: *this made relative to base.
Does not resolve ([fs.class.path]) symlinks.
Does not first normalize ([fs.path.generic]) *this or base.
[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.
On Windows, the returned path's directory-separator characters will be backslashes rather than slashes, but that does not affect path equality.
— end example]
[Note 2: 
If symlink following semantics are desired, use the operational function relative().
— end note]
[Note 3: 
If normalization ([fs.path.generic]) is needed to ensure consistent matching of elements, apply lexically_normal() to *this, base, or both.
— end note]
path lexically_proximate(const path& base) const;
Returns: If the value of lexically_relative(base) is not an empty path, return it.
Otherwise return *this.
[Note 4: 
If symlink following semantics are desired, use the operational function proximate().
— end note]
[Note 5: 
If normalization ([fs.path.generic]) is needed to ensure consistent matching of elements, apply lexically_normal() to *this, base, or both.
— end note]

31.12.6.6 Iterators [fs.path.itr]

Path iterators iterate over the elements of the pathname in the generic format.
A path​::​iterator is a constant iterator meeting all the requirements of a bidirectional iterator 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.
Its value_type is path.
Calling any non-const member function of a path object invalidates all iterators referring to elements of that object.
For the elements of the pathname in the generic format, the forward traversal order is as follows:
The backward traversal order is the reverse of forward traversal.
iterator begin() const;
Returns: An iterator for the first present element in the traversal list above.
If no elements are present, the end iterator.
iterator end() const;
Returns: The end iterator.

31.12.6.7 Inserter and extractor [fs.path.io]

template<class charT, class traits> friend basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const path& p);
Effects: Equivalent to os << quoted(p.string<charT, traits>()).
[Note 1: 
The quoted function is described in [quoted.manip].
— end note]
Returns: os.
template<class charT, class traits> friend basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, path& p);
Effects: Equivalent to: basic_string<charT, traits> tmp; is >> quoted(tmp); p = tmp;
Returns: is.

31.12.6.8 Non-member functions [fs.path.nonmember]

void swap(path& lhs, path& rhs) noexcept;
Effects: Equivalent to lhs.swap(rhs).
size_t hash_value(const path& p) noexcept;
Returns: A hash value for the path p.
If for two paths, p1 == p2 then hash_value(p1) == hash_value(p2).
friend bool operator==(const path& lhs, const path& rhs) noexcept;
Returns: lhs.compare(rhs) == 0.
[Note 1: 
Path equality and path equivalence have different semantics.
  • Equality is determined by the path non-member operator==, which considers the two paths' lexical representations only.
    [Example 1: 
    path("foo") == "bar" is never true.
    — end example]
  • Equivalence is determined by the equivalent() non-member function, which determines if two paths resolve ([fs.class.path]) to the same file system entity.
    [Example 2: 
    equivalent("foo", "bar") will be true when both paths resolve to the same file.
    — end example]
— end note]
friend strong_ordering operator<=>(const path& lhs, const path& rhs) noexcept;
Returns: lhs.compare(rhs) <=> 0.
friend path operator/(const path& lhs, const path& rhs);
Effects: Equivalent to: return path(lhs) /= rhs;

31.12.6.9 Hash support [fs.path.hash]

template<> struct hash<filesystem::path>;
For an object p of type filesystem​::​path, hash<filesystem​::​path>()(p) evaluates to the same result as filesystem​::​hash_value(p).

31.12.7 Class filesystem_error [fs.class.filesystem.error]

31.12.7.1 General [fs.class.filesystem.error.general]

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; }; }
The class filesystem_error defines the type of objects thrown as exceptions to report file system errors from functions described in subclause [filesystems].

31.12.7.2 Members [fs.filesystem.error.members]

Constructors are provided that store zero, one, or two paths associated with an error.
filesystem_error(const string& what_arg, error_code ec);
Postconditions:
  • code() == ec,
  • path1().empty() == true,
  • path2().empty() == true, and
  • string_view(what()).find(what_arg.c_str()) != string_view​::​npos.
filesystem_error(const string& what_arg, const path& p1, error_code ec);
Postconditions:
  • code() == ec,
  • path1() returns a reference to the stored copy of p1,
  • path2().empty() == true, and
  • string_view(what()).find(what_arg.c_str()) != string_view​::​npos.
filesystem_error(const string& what_arg, const path& p1, const path& p2, error_code ec);
Postconditions:
  • code() == ec,
  • path1() returns a reference to the stored copy of p1,
  • path2() returns a reference to the stored copy of p2, and
  • string_view(what()).find(what_arg.c_str()) != string_view​::​npos.
const path& path1() const noexcept;
Returns: A reference to the copy of p1 stored by the constructor, or, if none, an empty path.
const path& path2() const noexcept;
Returns: A reference to the copy of p2 stored by the constructor, or, if none, an empty path.
const char* what() const noexcept override;
Returns: An ntbs that incorporates the what_arg argument supplied to the constructor.
The exact format is unspecified.
Implementations should include the system_error​::​what() string and the pathnames of path1 and path2 in the native format in the returned string.

31.12.8 Enumerations [fs.enum]

31.12.8.1 Enum path​::​format [fs.enum.path.format]

This enum specifies constants used to identify the format of the character sequence, with the meanings listed in Table 130.
Table 130: Enum path​::​format[tab:fs.enum.path.format]
Name
Meaning
native_format
The native pathname format.
generic_format
The generic pathname format.
auto_format
The interpretation of the format of the character sequence is implementation-defined.
The implementation may inspect the content of the character sequence to determine the format.
Recommended practice: For POSIX-based systems, native and generic formats are equivalent and the character sequence should always be interpreted in the same way.

31.12.8.2 Enum class file_type [fs.enum.file.type]

This enum class specifies constants used to identify file types, with the meanings listed in Table 131.
The values of the constants are distinct.
Table 131: Enum class file_type[tab:fs.enum.file.type]
Constant
Meaning
none
The type of the file has not been determined or an error occurred while trying to determine the type.
not_found
Pseudo-type indicating the file was not found.
[Note 1: 
The file not being found is not considered an error while determining the type of a file.
— end note]
regular
Regular file
directory
Directory file
symlink
Symbolic link file
block
Block special file
character
Character special file
fifo
FIFO or pipe file
socket
Socket file
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
unknown
The file exists but the type cannot be determined

31.12.8.3 Enum class copy_options [fs.enum.copy.opts]

The enum class type copy_options is a bitmask type ([bitmask.types]) that specifies bitmask constants used to control the semantics of copy operations.
The constants are specified in option groups with the meanings listed in Table 132.
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.
Every other constant in the table represents a distinct bitmask element.
Table 132: Enum class copy_options[tab:fs.enum.copy.opts]
Option group controlling copy_file function effects for existing target files
Constant
Meaning
none
(Default) Error; file already exists.
skip_existing
Do not overwrite existing file, do not report an error.
overwrite_existing
Overwrite the existing file.
update_existing
Overwrite the existing file if it is older than the replacement file.
Option group controlling copy function effects for subdirectories
Constant
Meaning
none
(Default) Do not copy subdirectories.
recursive
Recursively copy subdirectories and their contents.
Option group controlling copy function effects for symbolic links
Constant
Meaning
none
(Default) Follow symbolic links.
copy_symlinks
Copy symbolic links as symbolic links rather than copying the files that they point to.
skip_symlinks
Ignore symbolic links.
Option group controlling copy function effects for choosing the form of copying
Constant
Meaning
none
(Default) Copy content.
directories_only
Copy directory structure only, do not copy non-directory files.
create_symlinks
Make symbolic links instead of copies of files.
The source path shall be an absolute path unless the destination path is in the current directory.
create_hard_links
Make hard links instead of copies of files.

31.12.8.4 Enum class perms [fs.enum.perms]

The enum class type perms is a bitmask type ([bitmask.types]) that specifies bitmask constants used to identify file permissions, with the meanings listed in Table 133.
Table 133: Enum class perms[tab:fs.enum.perms]
Name
Value
POSIX
Definition or notes
(octal)
macro
none
0
There are no permissions set for the file.
owner_read
0400
S_IRUSR
Read permission, owner
owner_write
0200
S_IWUSR
Write permission, owner
owner_exec
0100
S_IXUSR
Execute/search permission, owner
owner_all
0700
S_IRWXU
Read, write, execute/search by owner;
owner_read | owner_write | owner_exec
group_read
040
S_IRGRP
Read permission, group
group_write
020
S_IWGRP
Write permission, group
group_exec
010
S_IXGRP
Execute/search permission, group
group_all
070
S_IRWXG
Read, write, execute/search by group;
group_read | group_write | group_exec
others_read
04
S_IROTH
Read permission, others
others_write
02
S_IWOTH
Write permission, others
others_exec
01
S_IXOTH
Execute/search permission, others
others_all
07
S_IRWXO
Read, write, execute/search by others;
others_read | others_write | others_exec
all
0777
owner_all | group_all | others_all
set_uid
04000
S_ISUID
Set-user-ID on execution
set_gid
02000
S_ISGID
Set-group-ID on execution
sticky_bit
01000
S_ISVTX
Operating system dependent.
mask
07777
all | set_uid | set_gid | sticky_bit
unknown
0xFFFF
The permissions are not known, such as when a file_status object is created without specifying the permissions

31.12.8.5 Enum class perm_options [fs.enum.perm.opts]

The enum class type perm_options is a bitmask type ([bitmask.types]) that specifies bitmask constants used to control the semantics of permissions operations, with the meanings listed in Table 134.
The bitmask constants are bitmask elements.
In Table 134 perm denotes a value of type perms passed to permissions.
Table 134: Enum class perm_options[tab:fs.enum.perm.opts]
Name
Meaning
replace
permissions shall replace the file's permission bits with perm
add
permissions shall replace the file's permission bits with the bitwise or of perm and the file's current permission bits.
remove
permissions shall replace the file's permission bits with the bitwise and of the complement of perm and the file's current permission bits.
nofollow
permissions shall change the permissions of a symbolic link itself rather than the permissions of the file the link resolves to.

31.12.8.6 Enum class directory_options [fs.enum.dir.opts]

The enum class type directory_options is a bitmask type ([bitmask.types]) that specifies bitmask constants used to identify directory traversal options, with the meanings listed in Table 135.
The constant none represents the empty bitmask; every other constant in the table represents a distinct bitmask element.
Table 135: Enum class directory_options[tab:fs.enum.dir.opts]
Name
Meaning
none
(Default) Skip directory symlinks, permission denied is an error.
follow_directory_symlink
Follow rather than skip directory symlinks.
skip_permission_denied
Skip directories that would otherwise result in permission denied.

31.12.9 Class file_status [fs.class.file.status]

31.12.9.1 General [fs.class.file.status.general]

namespace std::filesystem { class file_status { public: // [fs.file.status.cons], 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], modifiers void type(file_type ft) noexcept; void permissions(perms prms) noexcept; // [fs.file.status.obs], 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(); } }; }
An object of type file_status stores information about the type and permissions of a file.

31.12.9.2 Constructors [fs.file.status.cons]

explicit file_status(file_type ft, perms prms = perms::unknown) noexcept;
Postconditions: type() == ft and permissions() == prms.

31.12.9.3 Observers [fs.file.status.obs]

file_type type() const noexcept;
Returns: The value of type() specified by the postconditions of the most recent call to a constructor, operator=, or type(file_type) function.
perms permissions() const noexcept;
Returns: The value of permissions() specified by the postconditions of the most recent call to a constructor, operator=, or permissions(perms) function.

31.12.9.4 Modifiers [fs.file.status.mods]

void type(file_type ft) noexcept;
Postconditions: type() == ft.
void permissions(perms prms) noexcept;
Postconditions: permissions() == prms.

31.12.10 Class directory_entry [fs.class.directory.entry]

31.12.10.1 General [fs.class.directory.entry.general]

namespace std::filesystem { class directory_entry { public: // [fs.dir.entry.cons], 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], modifiers void 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], observers const 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], inserter template<class charT, class traits> friend basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const directory_entry& d); private: filesystem::path pathobject; // exposition only friend class directory_iterator; // exposition only }; }
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.
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]).
Such stored file attribute values are said to be cached.
[Note 1: 
For purposes of exposition, class directory_iterator ([fs.class.directory.iterator]) is shown above as a friend of class directory_entry.
Friendship allows the directory_iterator implementation to cache already available attribute values directly into a directory_entry object without the cost of an unneeded call to refresh().
— end note]
[Example 1: using namespace std::filesystem; // use possibly cached last write time to minimize disk accesses for (auto&& x : directory_iterator(".")) { std::cout << x.path() << " " << x.last_write_time() << std::endl; } // call refresh() to refresh a stale cache for (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.
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.
The code is portable to any implementation, regardless of whether or not it employs caching.
— end example]

31.12.10.2 Constructors [fs.dir.entry.cons]

explicit directory_entry(const filesystem::path& p); directory_entry(const filesystem::path& p, error_code& ec);
Effects: Calls refresh() or refresh(ec), respectively.
Postconditions: path() == p if no error occurs, otherwise path() == filesystem​::​path().
Throws: As specified in [fs.err.report].

31.12.10.3 Modifiers [fs.dir.entry.mods]

void assign(const filesystem::path& p); void assign(const filesystem::path& p, error_code& ec);
Effects: Equivalent to pathobject = p, then refresh() or refresh(ec), respectively.
If an error occurs, the values of any cached attributes are unspecified.
Throws: As specified in [fs.err.report].
void replace_filename(const filesystem::path& p); void replace_filename(const filesystem::path& p, error_code& ec);
Effects: Equivalent to pathobject.replace_filename(p), then refresh() or refresh(ec), respectively.
If an error occurs, the values of any cached attributes are unspecified.
Throws: As specified in [fs.err.report].
void refresh(); void refresh(error_code& ec) noexcept;
Effects: Stores the current values of any cached attributes of the file p resolves to.
If an error occurs, an error is reported ([fs.err.report]) and the values of any cached attributes are unspecified.
Throws: As specified in [fs.err.report].
[Note 1: 
Implementations of directory_iterator ([fs.class.directory.iterator]) are prohibited from directly or indirectly calling the refresh function as described in [fs.class.directory.iterator.general].
— end note]

31.12.10.4 Observers [fs.dir.entry.obs]

Unqualified function names in the Returns: elements of the directory_entry observers described below refer to members of the std​::​filesystem namespace.
const filesystem::path& path() const noexcept; operator const filesystem::path&() const noexcept;
Returns: pathobject.
bool exists() const; bool exists(error_code& ec) const noexcept;
Returns: exists(this->status()) or exists(this->status(ec)), respectively.
Throws: As specified in [fs.err.report].
bool is_block_file() const; bool is_block_file(error_code& ec) const noexcept;
Returns: is_block_file(this->status()) or is_block_file(this->status(ec)), respectively.
Throws: As specified in [fs.err.report].
bool is_character_file() const; bool is_character_file(error_code& ec) const noexcept;
Returns: is_character_file(this->status()) or is_character_file(this->status(ec)), respectively.
Throws: As specified in [fs.err.report].
bool is_directory() const; bool is_directory(error_code& ec) const noexcept;
Returns: is_directory(this->status()) or is_directory(this->status(ec)), respectively.
Throws: As specified in [fs.err.report].
bool is_fifo() const; bool is_fifo(error_code& ec) const noexcept;
Returns: is_fifo(this->status()) or is_fifo(this->status(ec)), respectively.
Throws: As specified in [fs.err.report].
bool is_other() const; bool is_other(error_code& ec) const noexcept;
Returns: is_other(this->status()) or is_other(this->status(ec)), respectively.
Throws: As specified in [fs.err.report].
bool is_regular_file() const; bool is_regular_file(error_code& ec) const noexcept;
Returns: is_regular_file(this->status()) or is_regular_file(this->status(ec)), respectively.
Throws: As specified in [fs.err.report].
bool is_socket() const; bool is_socket(error_code& ec) const noexcept;
Returns: is_socket(this->status()) or is_socket(this->status(ec)), respectively.
Throws: As specified in [fs.err.report].
Returns: is_symlink(this->symlink_status()) or is_symlink(this->symlink_status(ec)), respectively.
Throws: As specified in [fs.err.report].
uintmax_t file_size() const; uintmax_t file_size(error_code& ec) const noexcept;
Returns: If cached, the file size attribute value.
Otherwise, file_size(path()) or file_size(path(), ec), respectively.
Throws: As specified in [fs.err.report].
Returns: If cached, the hard link count attribute value.
Otherwise, hard_link_count(path()) or hard_link_count(path(), ec), respectively.
Throws: As specified in [fs.err.report].
file_time_type last_write_time() const; file_time_type last_write_time(error_code& ec) const noexcept;
Returns: If cached, the last write time attribute value.
Otherwise, last_write_time(path()) or last_write_time(path(), ec), respectively.
Throws: As specified in [fs.err.report].
file_status status() const; file_status status(error_code& ec) const noexcept;
Returns: If cached, the status attribute value.
Otherwise, status(path()) or status(path(), ec), respectively.
Throws: As specified in [fs.err.report].
Returns: If cached, the symlink status attribute value.
Otherwise, symlink_status(path()) or symlink_status(path(), ec), respectively.
Throws: As specified in [fs.err.report].
bool operator==(const directory_entry& rhs) const noexcept;
Returns: pathobject == rhs.pathobject.
strong_ordering operator<=>(const directory_entry& rhs) const noexcept;
Returns: pathobject <=> rhs.pathobject.

31.12.10.5 Inserter [fs.dir.entry.io]

template<class charT, class traits> friend basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const directory_entry& d);
Effects: Equivalent to: return os << d.path();

31.12.11 Class directory_iterator [fs.class.directory.iterator]

31.12.11.1 General [fs.class.directory.iterator.general]

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]) for each file in a directory or in an implementation-defined directory-like file type.
[Note 1: 
For iteration into subdirectories, see class recursive_directory_iterator ([fs.class.rec.dir.itr]).
— 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], 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 }; }
directory_iterator meets the Cpp17InputIterator requirements ([input.iterators]).
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.
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.
The end iterator is not dereferenceable.
Two end iterators are always equal.
An end iterator shall not be equal to a non-end iterator.
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/=.
Directory iteration shall not yield directory entries for the current (dot) and parent (dot-dot) directories.
The order of directory entries obtained by dereferencing successive increments of a directory_iterator is unspecified.
Constructors and non-const directory_iterator member functions store the values of any cached attributes ([fs.class.directory.entry]) in the directory_entry element returned by operator*().
directory_iterator member functions shall not directly or indirectly call any directory_entry refresh function.
[Note 2: 
The exact mechanism for storing cached attribute values is not exposed to users.
For exposition, class directory_iterator is shown in [fs.class.directory.entry] as a friend of class directory_entry.
— end note]
[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.
Recursively walking directory trees for purposes of removing and renaming entries might invalidate symbolic links that are being followed.
— end note]
[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.
See POSIX readdir.
— end note]

31.12.11.2 Members [fs.dir.itr.members]

directory_iterator() noexcept;
Effects: Constructs the end iterator.
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);
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.
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.
Throws: As specified in [fs.err.report].
[Note 1: 
To iterate over the current directory, use directory_iterator(".") rather than directory_iterator("").
— end note]
directory_iterator(const directory_iterator& rhs); directory_iterator(directory_iterator&& rhs) noexcept;
Postconditions: *this has the original value of rhs.
directory_iterator& operator=(const directory_iterator& rhs); directory_iterator& operator=(directory_iterator&& rhs) noexcept;
Effects: If *this and rhs are the same object, the member has no effect.
Postconditions: *this has the original value of rhs.
Returns: *this.
directory_iterator& operator++(); directory_iterator& increment(error_code& ec);
Effects: As specified for the prefix increment operation of Input iterators.
Returns: *this.
Throws: As specified in [fs.err.report].

31.12.11.3 Non-member functions [fs.dir.itr.nonmembers]

These functions enable range access for directory_iterator.
directory_iterator begin(directory_iterator iter) noexcept;
Returns: iter.
directory_iterator end(directory_iterator) noexcept;
Returns: directory_iterator().

31.12.12 Class recursive_directory_iterator [fs.class.rec.dir.itr]

31.12.12.1 General [fs.class.rec.dir.itr.general]

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.
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], 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], 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], 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 }; }
Calling options, depth, recursion_pending, pop or disable_recursion_pending on an iterator that is not dereferenceable results in undefined behavior.
The behavior of a recursive_directory_iterator is the same as a directory_iterator unless otherwise specified.
[Note 1: 
If the directory structure being iterated over contains cycles then it is possible that the end iterator is unreachable.
— end note]

31.12.12.2 Members [fs.rec.dir.itr.members]

recursive_directory_iterator() noexcept;
Effects: Constructs the end iterator.
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);
Effects: Constructs an iterator representing the first entry in the directory to which p resolves, if any; otherwise, the end iterator.
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.
Postconditions: options() == options for the signatures with a directory_options argument, otherwise options() == directory_options​::​none.
Throws: As specified in [fs.err.report].
[Note 1: 
Use recursive_directory_iterator(".") rather than recursive_directory_iterator("") to iterate over the current directory.
— end note]
[Note 2: 
By default, recursive_directory_iterator does not follow directory symlinks.
To follow directory symlinks, specify options as directory_options​::​follow_directory_symlink.
— end note]
recursive_directory_iterator(const recursive_directory_iterator& rhs);
Postconditions:
  • options() == rhs.options()
  • depth() == rhs.depth()
  • recursion_pending() == rhs.recursion_pending()
recursive_directory_iterator(recursive_directory_iterator&& rhs) noexcept;
Postconditions: options(), depth(), and recursion_pending() have the values that rhs.options(), rhs.depth(), and rhs.recursion_pending(), respectively, had before the function call.
recursive_directory_iterator& operator=(const recursive_directory_iterator& rhs);
Effects: If *this and rhs are the same object, the member has no effect.
Postconditions:
  • options() == rhs.options()
  • depth() == rhs.depth()
  • recursion_pending() == rhs.recursion_pending()
Returns: *this.
recursive_directory_iterator& operator=(recursive_directory_iterator&& rhs) noexcept;
Effects: If *this and rhs are the same object, the member has no effect.
Postconditions: options(), depth(), and recursion_pending() have the values that rhs.options(), rhs.depth(), and rhs.recursion_pending(), respectively, had before the function call.
Returns: *this.
directory_options options() const;
Returns: The value of the argument passed to the constructor for the options parameter, if present, otherwise directory_options​::​none.
Throws: Nothing.
int depth() const;
Returns: The current depth of the directory tree being traversed.
[Note 3: 
The initial directory is depth 0, its immediate subdirectories are depth 1, and so forth.
— end note]
Throws: Nothing.
bool recursion_pending() const;
Returns: true if disable_recursion_pending() has not been called subsequent to the prior construction or increment operation, otherwise false.
Throws: Nothing.
recursive_directory_iterator& operator++(); recursive_directory_iterator& increment(error_code& ec);
Effects: As specified for the prefix increment operation of Input iterators, except that:
  • 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().
  • Otherwise if recursion_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.
Returns: *this.
Throws: As specified in [fs.err.report].
void pop(); void pop(error_code& ec);
Effects: If depth() == 0, set *this to recursive_directory_iterator().
Otherwise, cease iteration of the directory currently being iterated over, and continue iteration over the parent directory.
Throws: As specified in [fs.err.report].
Remarks: Any copies of the previous value of *this are no longer required to be dereferenceable nor to be in the domain of ==.
void disable_recursion_pending();
Postconditions: recursion_pending() == false.
[Note 4: 
disable_recursion_pending() is used to prevent unwanted recursion into a directory.
— end note]

31.12.12.3 Non-member functions [fs.rec.dir.itr.nonmembers]

These functions enable use of recursive_directory_iterator with range-based for statements.
recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept;
Returns: iter.
recursive_directory_iterator end(recursive_directory_iterator) noexcept;
Returns: recursive_directory_iterator().

31.12.13 Filesystem operation functions [fs.op.funcs]

31.12.13.1 General [fs.op.funcs.general]

Filesystem operation functions query or modify files, including directories, in external storage.
[Note 1: 
Because hardware failures, network failures, file system races ([fs.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].
— end note]

31.12.13.2 Absolute [fs.op.absolute]

path filesystem::absolute(const path& p); path filesystem::absolute(const path& p, error_code& ec);
Effects: Composes an absolute path referencing the same file system location as p according to the operating system ([fs.conform.os]).
Returns: The composed path.
The signature with argument ec returns path() if an error occurs.
[Note 1: 
For the returned path, rp, rp.is_absolute() is true unless an error occurs.
— end note]
Throws: As specified in [fs.err.report].
[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]).
— end note]
[Note 3: 
Implementations are strongly encouraged to not query secondary storage, and not consider !exists(p) an error.
— end note]
[Example 1: 
For POSIX-based operating systems, absolute(p) is simply current_path()/p.
For Windows-based operating systems, absolute might have the same semantics as GetFullPathNameW.
— end example]

31.12.13.3 Canonical [fs.op.canonical]

path filesystem::canonical(const path& p); path filesystem::canonical(const path& p, error_code& ec);
Effects: Converts p to an absolute path that has no symbolic link, dot, or dot-dot elements in its pathname in the generic format.
Returns: A path that refers to the same file system object as absolute(p).
The signature with argument ec returns path() if an error occurs.
Throws: As specified in [fs.err.report].
Remarks: !exists(p) is an error.

31.12.13.4 Copy [fs.op.copy]

void filesystem::copy(const path& from, const path& to);
Effects: Equivalent to copy(from, to, copy_options​::​none).
void filesystem::copy(const path& from, const path& to, error_code& ec);
Effects: Equivalent to copy(from, to, copy_options​::​none, ec).
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);
Preconditions: At most one element from each option group ([fs.enum.copy.opts]) is set in options.
Effects: Before the first use of f and t:
  • 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).
  • Otherwise, if (options & copy_options::copy_symlinks) != copy_options::none then auto f = symlink_status(from) and if needed auto t = status(to).
  • Otherwise, auto f = status(from) and if needed auto t = status(to).
Effects are then as follows:
  • If f.type() or t.type() is an implementation-defined file type ([fs.enum.file.type]), then the effects are implementation-defined.
  • Otherwise, an error is reported as specified in [fs.err.report] if:
    • exists(f) is false, or
    • equivalent(from, to) is true, or
    • is_other(f) || is_other(t) is true, or
    • is_directory(f) && is_regular_file(t) is true.
  • Otherwise, if is_symlink(f), then:
    • If (options & copy_options​::​skip_symlinks) != copy_options​::​none then return.
    • Otherwise if !exists(t) && (options & copy_options::copy_symlinks) != copy_options::none then copy_symlink(from, to).
    • Otherwise report an error as specified in [fs.err.report].
  • Otherwise, if is_regular_file(f), then:
    • If (options & copy_options​::​directories_only) != copy_options​::​none, then return.
    • Otherwise, if (options & copy_options​::​create_symlinks) != copy_options​::​none, then create a symbolic link to the source file.
    • Otherwise, if (options & copy_options​::​create_hard_links) != copy_options​::​none, then create a hard link to the source file.
    • Otherwise, if is_directory(t), then copy_file(from, to/from.filename(), options).
    • Otherwise, copy_file(from, to, options).
  • Otherwise, if is_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).
  • Otherwise, if is_directory(f) && ((options & copy_options::recursive) != copy_options::none || options == copy_options::none) then:
    • If exists(t) is false, then create_directory(to, from).
    • Then, iterate over the files in from, as if by for (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].
  • Otherwise, for the signature with argument ec, ec.clear().
  • Otherwise, no effects.
Throws: As specified in [fs.err.report].
Remarks: For the signature with argument ec, any library functions called by the implementation shall have an error_code argument if applicable.
[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 Copy file [fs.op.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);
Returns: copy_file(from, to, copy_options​::​none) or
copy_file(from, to, copy_options​::​none, ec), respectively.
Throws: As specified in [fs.err.report].
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);
Preconditions: At most one element from each option group ([fs.enum.copy.opts]) is set in options.
Effects: As follows:
  • Report an error as specified in [fs.err.report] if:
    • is_regular_file(from) is false, or
    • exists(to) is true and is_regular_file(to) is false, or
    • exists(to) is true and equivalent(from, to) is true, or
    • exists(to) is true and (options & (copy_options::skip_existing | copy_options::overwrite_existing | copy_options::update_existing)) == copy_options::none
  • Otherwise, copy the contents and attributes of the file from resolves to, to the file to resolves to, if:
    • exists(to) is false, or
    • (options & copy_options​::​overwrite_existing) != copy_options​::​none, or
    • (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]).
  • Otherwise, no effects.
Returns: true if the from file was copied, otherwise false.
The signature with argument ec returns false if an error occurs.
Throws: As specified in [fs.err.report].
Complexity: At most one direct or indirect invocation of status(to).

31.12.13.7 Create directories [fs.op.create.directories]

bool filesystem::create_directories(const path& p); bool filesystem::create_directories(const path& p, error_code& ec);
Effects: Calls create_directory() for each element of p that does not exist.
Returns: true if a new directory was created for the directory p resolves to, otherwise false.
Throws: As specified in [fs.err.report].
Complexity: where n is the number of elements of p.

31.12.13.8 Create directory [fs.op.create.directory]

bool filesystem::create_directory(const path& p); bool filesystem::create_directory(const path& p, error_code& ec) noexcept;
Effects: Creates the directory p resolves to, as if by POSIX mkdir with a second argument of static_cast<int>(perms​::​all).
If mkdir fails because p resolves to an existing directory, no error is reported.
Otherwise on failure an error is reported.
Returns: true if a new directory was created, otherwise false.
Throws: As specified in [fs.err.report].
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;
Effects: Creates the directory p resolves to, with attributes copied from directory existing_p.
The set of attributes copied is operating system dependent.
If mkdir fails because p resolves to an existing directory, no error is reported.
Otherwise on failure an error is reported.
[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).
For Windows-based operating systems, the attributes are those copied by native API CreateDirectoryExW(existing_p.c_str(), p.c_str(), 0).
— end note]
Returns: true if a new directory was created with attributes copied from directory existing_p, otherwise false.
Throws: As specified in [fs.err.report].

31.12.13.9 Create directory symlink [fs.op.create.dir.symlk]

Effects: Establishes the postcondition, as if by POSIX symlink().
Postconditions: new_symlink resolves to a symbolic link file that contains an unspecified representation of to.
Throws: As specified in [fs.err.report].
[Note 1: 
Some operating systems require symlink creation to identify that the link is to a directory.
Thus, create_symlink() (instead of create_directory_symlink()) cannot be used reliably to create directory symlinks.
— end note]
[Note 2: 
Some operating systems do not support symbolic links at all or support them only for regular files.
Some file systems (such as the FAT file system) do not support symbolic links regardless of the operating system.
— end note]

31.12.13.10 Create hard link [fs.op.create.hard.lk]

Effects: Establishes the postcondition, as if by POSIX link().
Postconditions:
  • exists(to) && exists(new_hard_link) && equivalent(to, new_hard_link)
  • The contents of the file or directory to resolves to are unchanged.
Throws: As specified in [fs.err.report].
[Note 1: 
Some operating systems do not support hard links at all or support them only for regular files.
Some file systems (such as the FAT file system) do not support hard links regardless of the operating system.
Some file systems limit the number of links per file.
— end note]

31.12.13.12 Current path [fs.op.current.path]

path filesystem::current_path(); path filesystem::current_path(error_code& ec);
Returns: The absolute path of the current working directory, whose pathname in the native format is obtained as if by POSIX getcwd().
The signature with argument ec returns path() if an error occurs.
Throws: As specified in [fs.err.report].
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.
[Note 1: 
The current_path() name was chosen to emphasize that the returned value is a path, not just a single directory name.
— end note]
[Note 2: 
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.
— end note]
void filesystem::current_path(const path& p); void filesystem::current_path(const path& p, error_code& ec) noexcept;
Effects: Establishes the postcondition, as if by POSIX chdir().
Postconditions: equivalent(p, current_path()).
Throws: As specified in [fs.err.report].
[Note 3: 
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.
— end note]

31.12.13.13 Equivalent [fs.op.equivalent]

bool filesystem::equivalent(const path& p1, const path& p2); bool filesystem::equivalent(const path& p1, const path& p2, error_code& ec) noexcept;
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.
[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.
— end note]
Returns: true, if p1 and p2 resolve to the same file system entity, otherwise false.
The signature with argument ec returns false if an error occurs.
Throws: As specified in [fs.err.report].
Remarks: !exists(p1) || !exists(p2) is an error.

31.12.13.14 Exists [fs.op.exists]

bool filesystem::exists(file_status s) noexcept;
Returns: status_known(s) && s.type() != file_type​::​not_found.
bool filesystem::exists(const path& p); bool filesystem::exists(const path& p, error_code& ec) noexcept;
Let s be a file_status, determined as if by status(p) or status(p, ec), respectively.
Effects: The signature with argument ec calls ec.clear() if status_known(s).
Returns: exists(s).
Throws: As specified in [fs.err.report].

31.12.13.15 File size [fs.op.file.size]

uintmax_t filesystem::file_size(const path& p); uintmax_t filesystem::file_size(const path& p, error_code& ec) noexcept;
Effects: If exists(p) is false, an error is reported ([fs.err.report]).
Returns:
  • 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().
  • Otherwise, the result is implementation-defined.
The signature with argument ec returns static_cast<uintmax_t>(-1) if an error occurs.
Throws: As specified in [fs.err.report].

31.12.13.16 Hard link count [fs.op.hard.lk.ct]

Returns: The number of hard links for p.
The signature with argument ec returns static_cast<uintmax_t>(-1) if an error occurs.
Throws: As specified in [fs.err.report].

31.12.13.17 Is block file [fs.op.is.block.file]

bool filesystem::is_block_file(file_status s) noexcept;
Returns: s.type() == file_type​::​block.
bool filesystem::is_block_file(const path& p); bool filesystem::is_block_file(const path& p, error_code& ec) noexcept;
Returns: is_block_file(status(p)) or is_block_file(status(p, ec)), respectively.
The signature with argument ec returns false if an error occurs.
Throws: As specified in [fs.err.report].

31.12.13.18 Is character file [fs.op.is.char.file]

bool filesystem::is_character_file(file_status s) noexcept;
Returns: s.type() == file_type​::​character.
bool filesystem::is_character_file(const path& p); bool filesystem::is_character_file(const path& p, error_code& ec) noexcept;
Returns: is_character_file(status(p)) or is_character_file(status(p, ec)), respectively.

The signature with argument ec returns false if an error occurs.
Throws: As specified in [fs.err.report].

31.12.13.19 Is directory [fs.op.is.directory]

bool filesystem::is_directory(file_status s) noexcept;
Returns: s.type() == file_type​::​directory.
bool filesystem::is_directory(const path& p); bool filesystem::is_directory(const path& p, error_code& ec) noexcept;
Returns: is_directory(status(p)) or is_directory(status(p, ec)), respectively.
The signature with argument ec returns false if an error occurs.
Throws: As specified in [fs.err.report].

31.12.13.20 Is empty [fs.op.is.empty]

bool filesystem::is_empty(const path& p); bool filesystem::is_empty(const path& p, error_code& ec);
Effects:
  • Determine file_status s, as if by status(p) or status(p, ec), respectively.
  • For the signature with argument ec, return false if an error occurred.
  • Otherwise, if is_directory(s):
    • Create a variable itr, as if by directory_iterator itr(p) or directory_iterator itr(p, ec), respectively.
    • For the signature with argument ec, return false if an error occurred.
    • Otherwise, return itr == directory_iterator().
  • Otherwise:
    • Determine uintmax_t sz, as if by file_size(p) or file_size(p, ec), respectively.
    • For the signature with argument ec, return false if an error occurred.
    • Otherwise, return sz == 0.
Throws: As specified in [fs.err.report].

31.12.13.21 Is fifo [fs.op.is.fifo]

bool filesystem::is_fifo(file_status s) noexcept;
Returns: s.type() == file_type​::​fifo.
bool filesystem::is_fifo(const path& p); bool filesystem::is_fifo(const path& p, error_code& ec) noexcept;
Returns: is_fifo(status(p)) or is_fifo(status(p, ec)), respectively.
The signature with argument ec returns false if an error occurs.
Throws: As specified in [fs.err.report].

31.12.13.22 Is other [fs.op.is.other]

bool filesystem::is_other(file_status s) noexcept;
Returns: exists(s) && !is_regular_file(s) && !is_directory(s) && !is_symlink(s).
bool filesystem::is_other(const path& p); bool filesystem::is_other(const path& p, error_code& ec) noexcept;
Returns: is_other(status(p)) or is_other(status(p, ec)), respectively.
The signature with argument ec returns false if an error occurs.
Throws: As specified in [fs.err.report].

31.12.13.23 Is regular file [fs.op.is.regular.file]

bool filesystem::is_regular_file(file_status s) noexcept;
Returns: s.type() == file_type​::​regular.
bool filesystem::is_regular_file(const path& p);
Returns: is_regular_file(status(p)).
Throws: filesystem_error if status(p) would throw filesystem_error.
bool filesystem::is_regular_file(const path& p, error_code& ec) noexcept;
Effects: Sets ec as if by status(p, ec).
[Note 1: 
file_type​::​none, file_type​::​not_found and file_type​::​unknown cases set ec to error values.
To distinguish between cases, call the status function directly.
— end note]
Returns: is_regular_file(status(p, ec)).
Returns false if an error occurs.

31.12.13.24 Is socket [fs.op.is.socket]

bool filesystem::is_socket(file_status s) noexcept;
Returns: s.type() == file_type​::​socket.
bool filesystem::is_socket(const path& p); bool filesystem::is_socket(const path& p, error_code& ec) noexcept;
Returns: is_socket(status(p)) or is_socket(status(p, ec)), respectively.
The signature with argument ec returns false if an error occurs.
Throws: As specified in [fs.err.report].

31.12.13.26 Last write time [fs.op.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;
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().
The signature with argument ec returns file_time_type​::​min() if an error occurs.
Throws: As specified in [fs.err.report].
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;
Effects: Sets the time of last data modification of the file resolved to by p to new_time, as if by POSIX futimens().
Throws: As specified in [fs.err.report].
[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.
— end note]

31.12.13.27 Permissions [fs.op.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);
Preconditions: Exactly one of the perm_options constants replace, add, or remove is present in opts.
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.
The action is applied as if by POSIX fchmodat().
[Note 1: 
Conceptually permissions are viewed as bits, but the actual implementation can use some other mechanism.
— end note]
Throws: As specified in [fs.err.report].
Remarks: The second signature behaves as if it had an additional parameter perm_options opts with an argument of perm_options​::​replace.

31.12.13.28 Proximate [fs.op.proximate]

path filesystem::proximate(const path& p, error_code& ec);
Returns: proximate(p, current_path(), ec).
Throws: As specified in [fs.err.report].
path filesystem::proximate(const path& p, const path& base = current_path()); path filesystem::proximate(const path& p, const path& base, error_code& ec);
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.
Throws: As specified in [fs.err.report].

31.12.13.30 Relative [fs.op.relative]

path filesystem::relative(const path& p, error_code& ec);
Returns: relative(p, current_path(), ec).
Throws: As specified in [fs.err.report].
path filesystem::relative(const path& p, const path& base = current_path()); path filesystem::relative(const path& p, const path& base, error_code& ec);
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.
Throws: As specified in [fs.err.report].

31.12.13.31 Remove [fs.op.remove]

bool filesystem::remove(const path& p); bool filesystem::remove(const path& p, error_code& ec) noexcept;
Effects: If exists(symlink_status(p, ec)), the file p is removed as if by POSIX remove().
[Note 1: 
A symbolic link is itself removed, rather than the file it resolves to.
— end note]
Postconditions: exists(symlink_status(p)) is false.
Returns: false if p did not exist, otherwise true.
The signature with argument ec returns false if an error occurs.
Throws: As specified in [fs.err.report].

31.12.13.32 Remove all [fs.op.remove.all]

uintmax_t filesystem::remove_all(const path& p); uintmax_t filesystem::remove_all(const path& p, error_code& ec);
Effects: Recursively deletes the contents of p if it exists, then deletes file p itself, as if by POSIX remove().
[Note 1: 
A symbolic link is itself removed, rather than the file it resolves to.
— end note]
Postconditions: exists(symlink_status(p)) is false.
Returns: The number of files removed.
The signature with argument ec returns static_cast< uintmax_t>(-1) if an error occurs.
Throws: As specified in [fs.err.report].

31.12.13.33 Rename [fs.op.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;
Effects: Renames old_p to new_p, as if by POSIX rename().
[Note 1: 
  • If old_p and new_p resolve to the same existing file, no action is taken.
  • Otherwise, the rename can include the following effects:
    • if new_p resolves to an existing non-directory file, new_p is removed; otherwise,
    • 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.
A symbolic link is itself renamed, rather than the file it resolves to.
— end note]
Throws: As specified in [fs.err.report].

31.12.13.34 Resize file [fs.op.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;
Effects: Causes the size that would be returned by file_size(p) to be equal to new_size, as if by POSIX truncate().
Throws: As specified in [fs.err.report].

31.12.13.35 Space [fs.op.space]

space_info filesystem::space(const path& p); space_info filesystem::space(const path& p, error_code& ec) noexcept;
Returns: An object of type space_info.
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.
Any members for which the value cannot be determined shall be set to static_cast<uintmax_t>(-1).
For the signature with argument ec, all members are set to static_cast<uintmax_t>(-1) if an error occurs.
Throws: As specified in [fs.err.report].
Remarks: The value of member space_info​::​available is operating system dependent.
[Note 1: 
available might be less than free.
— end note]

31.12.13.36 Status [fs.op.status]

file_status filesystem::status(const path& p);
Effects: As if: 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;
Returns: See above.
Throws: filesystem_error.
[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.
— end note]
file_status filesystem::status(const path& p, error_code& ec) noexcept;
Effects: If possible, determines the attributes of the file p resolves to, as if by using POSIX stat() to obtain a POSIX struct stat.
If, during attribute determination, the underlying file system API reports an error, sets ec to indicate the specific error reported.
Otherwise, ec.clear().
[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).
— end note]
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.
Returns:
  • If ec != error_code():
    • 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).
    • Otherwise, if the specific error indicates that p can be resolved but the attributes cannot be determined, returns file_status(file_type​::​unknown).
    • Otherwise, returns file_status(file_type​::​none).
    [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.
    These distinctions are important to some use cases.
    — end note]
  • Otherwise,
    • If the attributes indicate a regular file, as if by POSIX S_ISREG, returns file_status(file_type​::​regular, prms).
      [Note 4: 
      file_type​::​regular implies appropriate <fstream> operations would succeed, assuming no hardware, permission, access, or file system race errors.
      Lack of file_type​::​regular does not necessarily imply <fstream> operations would fail on a directory.
      — end note]
    • Otherwise, if the attributes indicate a directory, as if by POSIX S_ISDIR, returns file_status(file_type​::​directory, prms).
      [Note 5: 
      file_type​::​directory implies that calling directory_iterator(p) would succeed.
      — end note]
    • Otherwise, if the attributes indicate a block special file, as if by POSIX S_ISBLK, returns file_status(file_type​::​block, prms).
    • Otherwise, if the attributes indicate a character special file, as if by POSIX S_ISCHR, returns file_status(file_type​::​character, prms).
    • Otherwise, if the attributes indicate a fifo or pipe file, as if by POSIX S_ISFIFO, returns file_status(file_type​::​fifo, prms).
    • Otherwise, if the attributes indicate a socket, as if by POSIX S_ISSOCK, returns file_status(file_type​::​socket, prms).
    • Otherwise, if the attributes indicate an implementation-defined file type ([fs.enum.file.type]), returns file_status(file_type​::​A, prms), where A is the constant for the implementation-defined file type.
    • Otherwise, returns file_status(file_type​::​unknown, prms).
Remarks: If a symbolic link is encountered during pathname resolution, pathname resolution continues using the contents of the symbolic link.

31.12.13.37 Status known [fs.op.status.known]

bool filesystem::status_known(file_status s) noexcept;
Returns: s.type() != file_type​::​none.

31.12.13.38 Symlink status [fs.op.symlink.status]

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.
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.
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).
The signature with argument ec returns file_status(file_type​::​none) if an error occurs.
Throws: As specified in [fs.err.report].
Remarks: Pathname resolution terminates if p names a symbolic link.

31.12.13.39 Temporary directory path [fs.op.temp.dir.path]

path filesystem::temp_directory_path(); path filesystem::temp_directory_path(error_code& ec);
Let p be an unspecified directory path suitable for temporary files.
Effects: If exists(p) is false or is_directory(p) is false, an error is reported ([fs.err.report]).
Returns: The path p.
The signature with argument ec returns path() if an error occurs.
Throws: As specified in [fs.err.report].
[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".
For Windows-based operating systems, an implementation might return the path reported by the Windows GetTempPath API function.
— end example]

31.12.13.40 Weakly canonical [fs.op.weakly.canonical]

path filesystem::weakly_canonical(const path& p); path filesystem::weakly_canonical(const path& p, error_code& ec);
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.
For the first form, canonical() is called without an error_code argument.
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.
Postconditions: The returned path is in normal form ([fs.path.generic]).
Returns: p with symlinks resolved and the result normalized ([fs.path.generic]).
Throws: As specified in [fs.err.report].