A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://timsong-cpp.github.io/cppwp/n4659/filesystems below:

[filesystems]

30 Input/output library [input.output] 30.10 File systems [filesystems] 30.10.1 General [fs.general]

This subclause describes operations on file systems and their components, such as paths, regular files, and directories.

30.10.2 Conformance [fs.conformance]

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

30.10.2.1 POSIX conformance [fs.conform.9945]

Some behavior is specified by reference to POSIX ([fs.norm.ref]). How such behavior is actually implemented is unspecified. [Note: This constitutes an “as if” rule allowing implementations to call native operating system or other APIs. end note]

Implementations are encouraged to 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 are encouraged to 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: 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: 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]

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

Some behavior is specified as being operating system dependent. 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.

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

Behavior is undefined if calls to functions provided by this subclause 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, Requires: is not specified for the function. [Note: 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]

30.10.3 Normative references [fs.norm.ref]

This subclause mentions commercially available operating systems for purposes of exposition.328

30.10.5 absolute path [fs.def.absolute.path]

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.

30.10.6 directory [fs.def.directory]

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.

30.10.7 file [fs.def.file]

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.

30.10.9 file system race [fs.def.race]

The condition that occurs when multiple threads, processes, or computers interleave access and modification of the same object within a file system.

30.10.10 filename [fs.def.filename]

The name of a file. Filenames dot and dot-dot, consisting solely of one and two period characters respectively, have special meaning. The following characteristics of filenames are operating system dependent:

30.10.11 hard link [fs.def.hardlink]

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: A hard link can be thought of as a shared-ownership smart pointer to a file.end note]

30.10.12 link [fs.def.link]

An object that associates a filename with a file. Several links can associate names with the same file.

30.10.14 native pathname format [fs.def.native]

The operating system dependent pathname format accepted by the host operating system.

30.10.17 parent directory [fs.def.parent]

⟨of a directory⟩ the directory that both contains a directory entry for the given directory and is represented by the filename dot-dot in the given directory.

30.10.18 parent directory [fs.def.parent.other]

⟨of other types of files⟩ a directory containing a directory entry for the file under discussion.

30.10.19 path [fs.def.path]

A sequence of elements that identify the location of a file within a filesystem. The elements are the root-nameopt, root-directoryopt, and an optional sequence of filenames. The maximum number of elements in the sequence is operating system dependent.

30.10.21 pathname resolution [fs.def.pathres]

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: POSIX specifies the mechanism in section 4.11, Pathname resolution. end example]

30.10.22 relative path [fs.def.rel.path]

A path that is not absolute, and as such, only unambiguously identifies the location of a file when resolved ([fs.def.pathres]) relative to an implied starting location. The elements of a path that determine if it is relative are operating system dependent. [Note: Pathnames “.” and “..” are relative paths. end note]

30.10.23 symbolic link [fs.def.symlink]

A type of file with the property that when the file is encountered during pathname resolution, a string stored by the file is used to modify the pathname resolution. [Note: 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]

30.10.24 Requirements [fs.req]

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 input iterator requirements and shall have a value type that is one of the encoded character types.

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

30.10.24.1 Namespaces and headers [fs.req.namespace]

Unless otherwise specified, references to entities described in this subclause are assumed to be qualified with ​::​std​::​filesystem​::​.

30.10.25 Header <filesystem> synopsis [fs.filesystem.syn]
namespace std::filesystem {
    class path;

    void swap(path& lhs, path& rhs) noexcept;
  size_t hash_value(const path& p) noexcept;

  bool operator==(const path& lhs, const path& rhs) noexcept;
  bool operator!=(const path& lhs, const path& rhs) noexcept;
  bool operator< (const path& lhs, const path& rhs) noexcept;
  bool operator<=(const path& lhs, const path& rhs) noexcept;
  bool operator> (const path& lhs, const path& rhs) noexcept;
  bool operator>=(const path& lhs, const path& rhs) noexcept;

  path operator/ (const path& lhs, const path& rhs);

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

    template <class Source>
    path u8path(const Source& source);
  template <class InputIterator>
    path u8path(InputIterator first, InputIterator last);

    class filesystem_error;

    class directory_entry;

    class directory_iterator;

    directory_iterator begin(directory_iterator iter) noexcept;
  directory_iterator end(const directory_iterator&) noexcept;

    class recursive_directory_iterator;

    recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept;
  recursive_directory_iterator end(const recursive_directory_iterator&) noexcept;

    class file_status;

  struct space_info {
    uintmax_t capacity;
    uintmax_t free;
    uintmax_t available;
  };

    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<trivial-clock>;

    path absolute(const path& p, const path& base = current_path());

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

  void copy(const path& from, const path& to);
  void copy(const path& from, const path& to, error_code& ec) noexcept;
  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) noexcept;

  bool copy_file(const path& from, const path& to);
  bool copy_file(const path& from, const path& to, error_code& ec) noexcept;
  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) noexcept;

  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) noexcept;

  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 exists(file_status s) noexcept;
  bool exists(const path& p);
  bool exists(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;

  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) noexcept;

  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) noexcept;

  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);
}

trivial-clock is an implementation-defined type that satisfies the TrivialClock requirements and that is capable of representing and measuring file time values. Implementations should ensure that the resolution and range of file_­time_­type reflect the operating system dependent resolution and range of file time values.

30.10.26 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: This supports two common use cases:

end note]

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

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

30.10.27 Class path [fs.class.path]

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

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;

        enum format;

        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();

        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);

        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);

        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);

        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;

        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::string    u8string() const;
    std::u16string u16string() const;
    std::u32string u32string() const;

        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::string    generic_u8string() const;
    std::u16string generic_u16string() const;
    std::u32string generic_u32string() const;

        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;

        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;

        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;

        path lexically_normal() const;
    path lexically_relative(const path& base) const;
    path lexically_proximate(const path& base) const;

        class iterator;
    using const_iterator = iterator;

    iterator begin() const;
    iterator end() const;
  };
}

value_­type is a typedef for the operating system dependent encoded character type used to represent pathnames.

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

30.10.27.2 path conversions [fs.path.cvt] 30.10.27.2.1 path argument format conversions [fs.path.fmt.cvt]

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

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 or a pathname in the native format. 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: Some operating systems may 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: 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: 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 may 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: If q is the result of converting any path at all, it is the result of converting p. end note]

30.10.27.2.2 path type and encoding conversions [fs.path.type.cvt]

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:

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.

30.10.27.3 path requirements [fs.path.req]

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

Functions taking template parameters named Source shall not participate in overload resolution unless either

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

30.10.27.4 path members [fs.path.member] 30.10.27.4.1 path constructors [fs.path.construct]

path() noexcept;

Effects: Constructs an object of class path.

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);

Requires: 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:

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: 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.def.native.encode]). The resulting wide string is then converted to a narrow character pathname string in the current native narrow encoding. If the native wide encoding is UTF-16 or UTF-32, and the current native narrow 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 narrow 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]

30.10.27.4.2 path 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.

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: A valid implementation is swap(p). end note]

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.

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.

30.10.27.4.3 path 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:

[Example: Even if //host is interpreted as a root-name, both of the paths path("//host")/"foo" and path("//host/")/"foo" equal "//host/foo".

Expression examples:

path("foo") / "";     path("foo") / "/bar"; 
path("foo") / "c:/bar";  path("foo") / "c:";      path("c:") / "";         path("c:foo") / "/bar";  path("c:foo") / "c:bar"; 

end example]

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));

30.10.27.4.4 path 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); 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);

Effects: Appends path(x).native() to the pathname in the native format. [Note: This directly manipulates the value of native() and may not be portable between operating systems. end note]

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

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

30.10.27.4.5 path modifiers [fs.path.modifiers]

void clear() noexcept;

Postconditions: empty() == true.

path& make_preferred();

[Example:

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();

Postconditions: !has_­filename().

Effects: Remove the generic format pathname of filename() from the generic format pathname.

[Example:

path("foo/bar").remove_filename(); path("foo/").remove_filename();    path("/foo").remove_filename();    path("/").remove_filename();       

end example]

path& replace_filename(const path& replacement);

Effects: Equivalent to:

remove_filename();
operator/=(replacement);

[Example:

path("/foo").replace_filename("bar");  path("/").replace_filename("bar");     

end example]

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

Effects:

void swap(path& rhs) noexcept;

Effects: Swaps the contents (in all formats) of the two paths.

Complexity: Constant time.

30.10.27.4.6 path native format observers [fs.path.native.obs]

const string_type& native() const noexcept;

Returns: The pathname in the native format.

const value_type* c_str() const noexcept;

Returns: Equivalent to native().c_­str().

operator string_type() const;

[Note: Conversion to string_­type is provided so that an object of class path can be given as an argument to existing standard library file stream constructors and open functions. end note]

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

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::string u8string() const; std::u16string u16string() const; std::u32string u32string() const;

Remarks: Conversion, if any, is performed as specified by [fs.path.cvt]. The encoding of the string returned by u8string() is always UTF-8.

30.10.27.4.7 path generic format observers [fs.path.generic.obs]

[Example: 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::string 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]. The encoding of the string returned by generic_­u8string() is always UTF-8.

30.10.27.4.8 path compare [fs.path.compare]

int compare(const path& p) const noexcept;

Returns:

Remarks: The elements are determined as if by iteration over the half-open range [begin(), end()) for *this and p.

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

Returns: compare(path(s)).

int compare(const value_type* s) const

Returns: compare(path(s)).

30.10.27.4.9 path 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;

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(), beginning with the first filename after root-path. Otherwise, path().

path parent_path() const;

Returns: *this if !has_­relative_­path(), 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:

path("/foo/bar.txt").filename();   path("/foo/bar").filename();       path("/foo/bar/").filename();      path("/").filename();              path("//host").filename();         path(".").filename();              path("..").filename();             

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

[Example:

std::cout << path("/foo/bar.txt").stem(); path p = "foo.bar.baz.tar";
for (; !p.extension().empty(); p = p.stem())
  std::cout << p.extension() << '\n';
      

end example]

path extension() const;

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

[Example:

path("/foo/bar.txt").extension();  path("/foo/bar").extension();      path("/foo/.profile").extension(); path(".bar").extension();          path("..bar").extension();         

end example]

[Note: 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: On non-POSIX operating systems, for a path p, it may not be the case that p.stem() + p.extension() == p.filename(), even though the generic format pathnames are the same. end note]

30.10.27.4.10 path query [fs.path.query]

bool empty() const noexcept;

Returns: true if the pathname in the generic format is empty, else 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, else false.

[Example: path("/").is_­absolute() is true for POSIX-based operating systems, and false for Windows-based operating systems. end example]

bool is_relative() const;

30.10.27.4.11 path generation [fs.path.gen]

path lexically_normal() const;

Returns: A path whose pathname in the generic format is the normal form of the pathname in the generic format of *this.

[Example:

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;

Returns: *this made relative to base. Does not resolve symlinks. Does not first normalize *this or base.

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, returns path(). Determines the first mismatched element of *this and base as if by:

auto [a, b] = mismatch(begin(), end(), base.begin(), base.end());

Then,

[Example:

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: If symlink following semantics are desired, use the operational function relative(). end note]

[Note: If normalization 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: If symlink following semantics are desired, use the operational function proximate(). end note]

[Note: If normalization is needed to ensure consistent matching of elements, apply lexically_­normal() to *this, base, or both. end note]

30.10.27.5 path iterators [fs.path.itr]

Path iterators iterate over the elements of the pathname in the generic format.

A path​::​iterator is a constant iterator satisfying 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.

30.10.27.6 path 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).

bool operator< (const path& lhs, const path& rhs) noexcept;

Returns: lhs.compare(rhs) < 0.

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

bool operator> (const path& lhs, const path& rhs) noexcept;

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

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

Returns: !(lhs < rhs) && !(rhs < lhs).

[Note: Path equality and path equivalence have different semantics.

Programmers wishing to determine if two paths are “the same” must decide if “the same” means “the same representation” or “resolve to the same actual file”, and choose the appropriate function accordingly. end note]

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

path operator/ (const path& lhs, const path& rhs);

Effects: Equivalent to: return path(lhs) /= rhs;

30.10.27.6.1 path inserter and extractor [fs.path.io]

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

Effects: Equivalent to: os << quoted(p.string<charT, traits>()); [Note: The quoted function is described in [quoted.manip]. end note]

template <class charT, class traits> 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;
30.10.27.6.2 path factory functions [fs.path.factory]

template <class Source> path u8path(const Source& source); template <class InputIterator> path u8path(InputIterator first, InputIterator last);

Requires: The source and [first, last) sequences are UTF-8 encoded. The value type of Source and InputIterator is char.

Returns:

Remarks: Argument format conversion applies to the arguments for these functions. How Unicode encoding conversions are performed is unspecified.

[Example: A string is to be read from a database that is encoded in UTF-8, and used to create a directory using the native encoding for filenames:

namespace fs = std::filesystem;
std::string utf8_string = read_utf8_data();
fs::create_directory(fs::u8path(utf8_string));

For POSIX-based operating systems with the native narrow encoding set to UTF-8, no encoding or type conversion occurs.

For POSIX-based operating systems with the native narrow encoding not set to UTF-8, a conversion to UTF-32 occurs, followed by a conversion to the current native narrow encoding. Some Unicode characters may have no native character set representation.

For Windows-based operating systems a conversion from UTF-8 to UTF-16 occurs. end example]

30.10.28 Class filesystem_­error [fs.class.filesystem_error]
namespace std::filesystem {
  class filesystem_error : public system_error {
  public:
    filesystem_error(const string& what_arg, error_code ec);
    filesystem_error(const string& what_arg,
                     const path& p1, error_code ec);
    filesystem_error(const string& what_arg,
                     const path& p1, const path& p2, error_code ec);

    const path& path1() const noexcept;
    const path& path2() const noexcept;
    const char* what() const noexcept override;
  };
}

The class filesystem_­error defines the type of objects thrown as exceptions to report file system errors from functions described in this subclause.

30.10.28.1 filesystem_­error members [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: The postconditions of this function are indicated in Table 119.

Table

119

filesystem_­error(const string&, error_­code)

effects


Expression Value runtime_­error​::​what() what_­arg.c_­str() code() ec path1().empty() true path2().empty() true

filesystem_error(const string& what_arg, const path& p1, error_code ec);

Postconditions: The postconditions of this function are indicated in Table 120.

Table

120

filesystem_­error(const string&, const path&, error_­code)

effects


Expression Value runtime_­error​::​what() what_­arg.c_­str() code() ec path1() Reference to stored copy of p1 path2().empty() true

filesystem_error(const string& what_arg, const path& p1, const path& p2, error_code ec);

Postconditions: The postconditions of this function are indicated in Table 121.

Table

121

filesystem_­error(const string&, const path&, const path&, error_­code)

effects


Expression Value runtime_­error​::​what() what_­arg.c_­str() code() ec path1() Reference to stored copy of p1 path2() Reference to stored copy of p2

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: A string containing runtime_­error​::​what(). The exact format is unspecified. Implementations are encouraged but not required to include path1.native_­string() if not empty, path2.native_­string() if not empty, and system_­error​::​what() strings in the returned string.

30.10.29 Enumerations [fs.enum] 30.10.29.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 122.

Table

122

— 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. [Note: For POSIX-based systems, native and generic formats are equivalent and the character sequence should always be interpreted in the same way. end note] 30.10.29.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 123.

Table

123

— Enum class

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: 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 could not be determined 30.10.29.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 124. Constant none is shown in each option group for purposes of exposition; implementations shall provide only a single definition.

Table

124

— Enum class

copy_­options
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 sub-directories Constant Meaning none (Default) Do not copy sub-directories. recursive Recursively copy sub-directories 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. 30.10.29.4 Enum class perms [fs.enum.perms]

The enum class type perms is a bitmask type that specifies bitmask constants used to identify file permissions, with the meanings listed in Table 125.

Table

125

— Enum class

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 30.10.29.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 126. The bitmask constants are bitmask elements. In Table 126 perm denotes a value of type perms passed to permissions.

Table

126

— Enum class

perm_­options
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. 30.10.29.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 127.

Table

127

— Enum class

directory_­options
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. 30.10.30 Class file_­status [fs.class.file_status]
namespace std::filesystem {
  class file_status {
  public:
        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();

        file_status& operator=(const file_status&) noexcept = default;
    file_status& operator=(file_status&&) noexcept = default;

        void       type(file_type ft) noexcept;
    void       permissions(perms prms) noexcept;

        file_type  type() const noexcept;
    perms      permissions() const noexcept;
  };
}

An object of type file_­status stores information about the type and permissions of a file.

30.10.30.1 file_­status constructors [fs.file_status.cons]

explicit file_status(file_type ft, perms prms = perms::unknown) noexcept;

Postconditions: type() == ft and permissions() == prms.

30.10.30.2 file_­status 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.

30.10.30.3 file_­status modifiers [fs.file_status.mods]

void type(file_type ft) noexcept;

Postconditions: type() == ft.

void permissions(perms prms) noexcept;

Postconditions: permissions() == prms.

30.10.31 Class directory_­entry [fs.class.directory_entry]
namespace std::filesystem {
  class directory_entry {
  public:
        directory_entry() noexcept = default;
    directory_entry(const directory_entry&) = default;
    directory_entry(directory_entry&&) noexcept = default;
    explicit directory_entry(const path& p);
    directory_entry(const path& p, error_code& ec);
    ~directory_entry();

        directory_entry& operator=(const directory_entry&) = default;
    directory_entry& operator=(directory_entry&&) noexcept = default;

        void assign(const path& p);
    void assign(const path& p, error_code& ec);
    void replace_filename(const path& p);
    void replace_filename(const path& p, error_code& ec);
    void refresh();
    void refresh(error_code& ec) noexcept;

        const path& path() const noexcept;
    operator const 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;
    bool operator==(const directory_entry& rhs) const noexcept;
    bool operator!=(const directory_entry& rhs) const noexcept;
    bool operator<=(const directory_entry& rhs) const noexcept;
    bool operator> (const directory_entry& rhs) const noexcept;
    bool operator>=(const directory_entry& rhs) const noexcept;

  private:
    path pathobject;                     friend class directory_iterator;   };
}

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 are encouraged to 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: 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:

using namespace std::filesystem;

for (auto&& x : directory_iterator("."))
{
  std::cout << x.path() << " " << x.last_write_time() << std::endl;
}

for (auto&& x : directory_iterator("."))
{
  lengthy_function(x.path());    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]

30.10.31.1 directory_­entry constructors [fs.dir.entry.cons]

explicit directory_entry(const path& p); directory_entry(const path& p, error_code& ec);

Effects: Constructs an object of type directory_­entry, then refresh() or refresh(ec), respectively.

Postconditions: path() == p if no error occurs, otherwise path() == std​::​filesystem​::​path().

30.10.31.2 directory_­entry modifiers [fs.dir.entry.mods]

void assign(const path& p); void assign(const 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.

void replace_filename(const path& p); void replace_filename(const 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.

[Note: Implementations of directory_­iterator ([fs.class.directory_iterator]) are prohibited from directly or indirectly calling the refresh function since it must access the external file system, and the objective of caching is to avoid unnecessary file system accesses. end note]

30.10.31.3 directory_­entry 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 path& path() const noexcept; operator const path&() const noexcept;

bool exists() const; bool exists(error_code& ec) const noexcept;

Returns: exists(this->status()) or exists(this->status(), ec), respectively.

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.

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.

bool is_directory() const; bool is_directory(error_code& ec) const noexcept;

Returns: is_­directory(this->status()) or is_­directory(this->status(), ec), respectively.

bool is_fifo() const; bool is_fifo(error_code& ec) const noexcept;

Returns: is_­fifo(this->status()) or is_­fifo(this->status(), ec), respectively.

bool is_other() const; bool is_other(error_code& ec) const noexcept;

Returns: is_­other(this->status()) or is_­other(this->status(), ec), respectively.

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.

bool is_socket() const; bool is_socket(error_code& ec) const noexcept;

Returns: is_­socket(this->status()) or is_­socket(this->status(), ec), respectively.

bool is_symlink() const; bool is_symlink(error_code& ec) const noexcept;

Returns: is_­symlink(this->symlink_­status()) or is_­symlink(this->symlink_­status(), ec), respectively.

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.

uintmax_t hard_link_count() const; uintmax_t hard_link_count(error_code& ec) const noexcept;

Returns: If cached, the hard link count attribute value. Otherwise, hard_­link_­count(path()) or hard_­link_­count(path(), ec), respectively.

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.

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.

file_status symlink_status() const; file_status symlink_status(error_code& ec) const noexcept;

Returns: If cached, the symlink status attribute value. Otherwise, symlink_­status(path()) or symlink_­status(path(), ec), respectively.

bool operator==(const directory_entry& rhs) const noexcept;

Returns: pathobject == rhs.pathobject.

bool operator!=(const directory_entry& rhs) const noexcept;

Returns: pathobject != rhs.pathobject.

bool operator< (const directory_entry& rhs) const noexcept;

Returns: pathobject < rhs.pathobject.

bool operator<=(const directory_entry& rhs) const noexcept;

Returns: pathobject <= rhs.pathobject.

bool operator> (const directory_entry& rhs) const noexcept;

Returns: pathobject > rhs.pathobject.

bool operator>=(const directory_entry& rhs) const noexcept;

Returns: pathobject >= rhs.pathobject.

30.10.32 Class directory_­iterator [fs.class.directory_iterator]

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: For iteration into sub-directories, 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&;

        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) noexcept;
    directory_iterator(const path& p, directory_options options,
                       error_code& ec) noexcept;
    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) noexcept;

      };
}

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 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: 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: Programs performing directory iteration may wish to test if the path obtained by dereferencing a directory iterator actually exists. It could be a symbolic link to a non-existent file. Programs recursively walking directory trees for purposes of removing and renaming entries may wish to avoid following symbolic links. end note]

[Note: 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_­r. end note]

30.10.32.1 directory_­iterator 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) noexcept; directory_iterator(const path& p, directory_options options, error_code& ec) noexcept;

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.

[Note: 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;

Effects: Constructs an object of class directory_­iterator.

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.

directory_iterator& operator++(); directory_iterator& increment(error_code& ec) noexcept;

Effects: As specified for the prefix increment operation of Input iterators.

30.10.32.2 directory_­iterator non-member functions [fs.dir.itr.nonmembers]

These functions enable range access for directory_­iterator.

directory_iterator begin(directory_iterator iter) noexcept;

directory_iterator end(const directory_iterator&) noexcept;

Returns: directory_­iterator().

30.10.33 Class recursive_­directory_­iterator [fs.class.rec.dir.itr]

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 sub-directories.

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&;

        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) noexcept;
    recursive_directory_iterator(const path& p, error_code& ec) noexcept;
    recursive_directory_iterator(const recursive_directory_iterator& rhs);
    recursive_directory_iterator(recursive_directory_iterator&& rhs) noexcept;
    ~recursive_directory_iterator();

        directory_options  options() const;
    int                depth() const;
    bool               recursion_pending() const;

    const directory_entry& operator*() const;
    const directory_entry* operator->() const;

        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) noexcept;

    void pop();
    void pop(error_code& ec);
    void disable_recursion_pending();

      };
}

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: If the directory structure being iterated over contains cycles then the end iterator may be unreachable. end note]

30.10.33.1 recursive_­directory_­iterator 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) noexcept; recursive_directory_iterator(const path& p, error_code& ec) noexcept;

Effects: Constructs a iterator representing the first entry in the directory p resolves to, 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.

[Note: To iterate over the current directory, use recursive_­directory_­iterator(".") rather than recursive_­directory_­iterator(""). end note]

[Note: 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);

Effects: Constructs an object of class recursive_­directory_­iterator.

Postconditions:

recursive_directory_iterator(recursive_directory_iterator&& rhs) noexcept;

Effects: Constructs an object of class recursive_­directory_­iterator.

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:

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.

directory_options options() const;

Returns: The value of the argument passed to the constructor for the options parameter, if present, otherwise directory_­options​::​none.

int depth() const;

Returns: The current depth of the directory tree being traversed. [Note: The initial directory is depth 0, its immediate subdirectories are depth 1, and so forth. end note]

bool recursion_pending() const;

Returns: true if disable_­recursion_­pending() has not been called subsequent to the prior construction or increment operation, otherwise false.

recursive_directory_iterator& operator++(); recursive_directory_iterator& increment(error_code& ec) noexcept;

Effects: As specified for the prefix increment operation of Input iterators, except that:

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.

void disable_recursion_pending();

Postconditions: recursion_­pending() == false.

[Note: disable_­recursion_­pending() is used to prevent unwanted recursion into a directory. end note]

30.10.33.2 recursive_­directory_­iterator 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;

recursive_directory_iterator end(const recursive_directory_iterator&) noexcept;

Returns: recursive_­directory_­iterator().

30.10.34 Filesystem operation functions [fs.op.funcs]

Filesystem operation functions query or modify files, including directories, in external storage.

[Note: Because hardware failures, network failures, file system races, and many other kinds of errors occur frequently in file system operations, users should be aware that any filesystem operation function, no matter how apparently innocuous, may encounter an error; see [fs.err.report]. end note]

30.10.34.1 Absolute [fs.op.absolute]

path absolute(const path& p); path 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: For the returned path, rp, rp.is_­absolute() is true unless an error occurs. end note]

[Note: To resolve symlinks, or perform other sanitization which might require queries to secondary storage, such as hard disks, consider canonical ([fs.op.canonical]). end note]

[Note: Implementations are strongly encouraged to not query secondary storage, and not consider !exists(p) an error. end note]

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

30.10.34.2 Canonical [fs.op.canonical]

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

Effects: Converts p, which must exist, 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, base). For the overload without a base argument, base is current_­path(). Signatures with argument ec return path() if an error occurs.

Remarks: !exists(p) is an error.

30.10.34.3 Copy [fs.op.copy]

void copy(const path& from, const path& to);

Effects: Equivalent to copy(from, to, copy_­options​::​none).

void copy(const path& from, const path& to, error_code& ec) noexcept;

Effects: Equivalent to copy(from, to, copy_­options​::​none, 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) noexcept;

Effects: Before the first use of f and t:

Effects are then as follows:

Remarks: For the signature with argument ec, any library functions called by the implementation shall have an error_­code argument if applicable.

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

30.10.34.4 Copy file [fs.op.copy_file]

bool copy_file(const path& from, const path& to); bool copy_file(const path& from, const path& to, error_code& ec) noexcept;

Returns: copy_­file(from, to, copy_­options​::​none) or
copy_­file(from, to, copy_­options​::​none, ec), respectively.

bool copy_file(const path& from, const path& to, copy_options options); bool copy_file(const path& from, const path& to, copy_options options, error_code& ec) noexcept;

Effects: As follows:

Returns: true if the from file was copied, otherwise false. The signature with argument ec returns false if an error occurs.

Complexity: At most one direct or indirect invocation of status(to).

30.10.34.5 Copy symlink [fs.op.copy_symlink]

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;

Effects: Equivalent to function(read_­symlink(existing_­symlink), new_­symlink) or
function(read_­symlink(existing_­symlink, ec), new_­symlink, ec), respectively, where in each case function is create_­symlink or create_­directory_­symlink as appropriate.

30.10.34.6 Create directories [fs.op.create_directories]

bool create_directories(const path& p); bool create_directories(const path& p, error_code& ec) noexcept;

Effects: Establishes the postcondition by calling create_­directory() for any element of p that does not exist.

Postconditions: is_­directory(p).

Returns: true if a new directory was created, otherwise false. The signature with argument ec returns false if an error occurs.

Complexity: O(n) where n is the number of elements of p that do not exist.

30.10.34.7 Create directory [fs.op.create_directory]

bool create_directory(const path& p); bool create_directory(const path& p, error_code& ec) noexcept;

Effects: Establishes the postcondition by attempting to create the directory p resolves to, as if by POSIX mkdir() with a second argument of static_­cast<int>(perms​::​all). Creation failure because p resolves to an existing directory shall not be treated as an error.

Postconditions: is_­directory(p).

Returns: true if a new directory was created, otherwise false. The signature with argument ec returns false if an error occurs.

bool create_directory(const path& p, const path& existing_p); bool create_directory(const path& p, const path& existing_p, error_code& ec) noexcept;

Effects: Establishes the postcondition by attempting to create the directory p resolves to, with attributes copied from directory existing_­p. The set of attributes copied is operating system dependent. Creation failure because p resolves to an existing directory shall not be treated as an error. [Note: 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]

Postconditions: is_­directory(p).

Returns: true if a new directory was created, otherwise false. The signature with argument ec returns false if an error occurs.

30.10.34.8 Create directory symlink [fs.op.create_dir_symlk]

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;

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.

[Note: Some operating systems require symlink creation to identify that the link is to a directory. Portable code should use create_­directory_­symlink() to create directory symlinks rather than create_­symlink() end note]

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

30.10.34.9 Create hard link [fs.op.create_hard_lk]

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;

Effects: Establishes the postcondition, as if by POSIX link().

Postconditions:

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

30.10.34.10 Create symlink [fs.op.create_symlink]

void create_symlink(const path& to, const path& new_symlink); void create_symlink(const path& to, const path& new_symlink, error_code& ec) noexcept;

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.

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

30.10.34.11 Current path [fs.op.current_path]

path current_path(); path 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.

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: The current_­path() name was chosen to emphasize that the returned value is a path, not just a single directory name. end note]

[Note: The current path as returned by many operating systems is a dangerous global variable. It may be changed unexpectedly by a third-party or system library functions, or by another thread. end note]

void current_path(const path& p); void current_path(const path& p, error_code& ec) noexcept;

Effects: Establishes the postcondition, as if by POSIX chdir().

Postconditions: equivalent(p, current_­path()).

[Note: The current path for many operating systems is a dangerous global state. It may be changed unexpectedly by a third-party or system library functions, or by another thread. end note]

30.10.34.12 Equivalent [fs.op.equivalent]

bool equivalent(const path& p1, const path& p2); bool equivalent(const path& p1, const path& p2, error_code& ec) noexcept;

Let s1 and s2 be file_­statuss, determined as if by status(p1) and status(p2), respectively.

Effects: Determines s1 and s2. If (!exists(s1) && !exists(s2)) || (is_­other(s1) && is_­other(s2)) an error is reported ([fs.err.report]).

Returns: true, if s1 == s2 and p1 and p2 resolve to the same file system entity, else false. The signature with argument ec returns false if an error occurs.

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. This is determined as if by the values of the POSIX stat structure, obtained as if by stat() for the two paths, having equal st_­dev values and equal st_­ino values.

30.10.34.13 Exists [fs.op.exists]

bool exists(file_status s) noexcept;

Returns: status_­known(s) && s.type() != file_­type​::​not_­found.

bool exists(const path& p); bool 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).

30.10.34.14 File size [fs.op.file_size]

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

Returns:

The signature with argument ec returns static_­cast<uintmax_­t>(-1) if an error occurs.

30.10.34.15 Hard link count [fs.op.hard_lk_ct]

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

Returns: The number of hard links for p. The signature with argument ec returns static_­cast<uintmax_­t>(-1) if an error occurs.

30.10.34.16 Is block file [fs.op.is_block_file]

bool is_block_file(file_status s) noexcept;

Returns: s.type() == file_­type​::​block.

bool is_block_file(const path& p); bool 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.

30.10.34.17 Is character file [fs.op.is_char_file]

bool is_character_file(file_status s) noexcept;

Returns: s.type() == file_­type​::​character.

bool is_character_file(const path& p); bool 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.

30.10.34.18 Is directory [fs.op.is_directory]

bool is_directory(file_status s) noexcept;

Returns: s.type() == file_­type​::​directory.

bool is_directory(const path& p); bool 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.

30.10.34.19 Is empty [fs.op.is_empty]

bool is_empty(const path& p); bool is_empty(const path& p, error_code& ec) noexcept;

Effects:

30.10.34.20 Is fifo [fs.op.is_fifo]

bool is_fifo(file_status s) noexcept;

Returns: s.type() == file_­type​::​fifo.

bool is_fifo(const path& p); bool 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.

30.10.34.21 Is other [fs.op.is_other]

bool is_other(file_status s) noexcept;

Returns: exists(s) && !is_­regular_­file(s) && !is_­directory(s) && !is_­symlink(s).

bool is_other(const path& p); bool 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.

30.10.34.22 Is regular file [fs.op.is_regular_file]

bool is_regular_file(file_status s) noexcept;

Returns: s.type() == file_­type​::​regular.

bool is_regular_file(const path& p);

Returns: is_­regular_­file(status(p)).

Throws: filesystem_­error if status(p) would throw filesystem_­error.

bool is_regular_file(const path& p, error_code& ec) noexcept;

Effects: Sets ec as if by status(p, ec). [Note: 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.

30.10.34.23 Is socket [fs.op.is_socket]

bool is_socket(file_status s) noexcept;

Returns: s.type() == file_­type​::​socket.

bool is_socket(const path& p); bool 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.

30.10.34.24 Is symlink [fs.op.is_symlink]

bool is_symlink(file_status s) noexcept;

Returns: s.type() == file_­type​::​symlink.

bool is_symlink(const path& p); bool is_symlink(const path& p, error_code& ec) noexcept;

Returns: is_­symlink(symlink_­status(p)) or is_­symlink(symlink_­status(p, ec)), respectively. The signature with argument ec returns false if an error occurs.

30.10.34.25 Last write time [fs.op.last_write_time]

file_time_type last_write_time(const path& p); file_time_type 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 structure member st_­mtime obtained as if by POSIX stat(). The signature with argument ec returns file_­time_­type​::​min() if an error occurs.

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;

Effects: Sets the time of last data modification of the file resolved to by p to new_­time, as if by POSIX futimens().

[Note: A postcondition of last_­write_­time(p) == new_­time is not specified since it might not hold for file systems with coarse time granularity. end note]

30.10.34.26 Permissions [fs.op.permissions]

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);

Requires: Exactly one of the perm_­options constants replace, add, or remove is present in opts.

Remarks: The second signature behaves as if it had an additional parameter perm_­options opts with an argument of perm_­options​::​replace.

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: Conceptually permissions are viewed as bits, but the actual implementation may use some other mechanism. end note]

30.10.34.27 Proximate [fs.op.proximate]

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

Returns: proximate(p, current_­path(), ec).

path proximate(const path& p, const path& base = current_path()); path 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.

30.10.34.28 Read symlink [fs.op.read_symlink]

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

Returns: If p resolves to a symbolic link, a path object containing the contents of that symbolic link. The signature with argument ec returns path() if an error occurs.

Throws: As specified in [fs.err.report]. [Note: It is an error if p does not resolve to a symbolic link. end note]

30.10.34.29 Relative [fs.op.relative]

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

Returns: relative(p, current_­path(), ec).

path relative(const path& p, const path& base = current_path()); path 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.

30.10.34.30 Remove [fs.op.remove]

bool remove(const path& p); bool 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: A symbolic link is itself removed, rather than the file it resolves to. end note]

Postconditions: !exists(symlink_­status(p)).

Returns: false if p did not exist, otherwise true. The signature with argument ec returns false if an error occurs.

30.10.34.31 Remove all [fs.op.remove_all]

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

Effects: Recursively deletes the contents of p if it exists, then deletes file p itself, as if by POSIX remove(). [Note: A symbolic link is itself removed, rather than the file it resolves to. end note]

Postconditions: !exists(symlink_­status(p)).

Returns: The number of files removed. The signature with argument ec returns static_­cast< uintmax_­t>(-1) if an error occurs.

30.10.34.32 Rename [fs.op.rename]

void rename(const path& old_p, const path& new_p); void 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:

A symbolic link is itself renamed, rather than the file it resolves to. end note]

30.10.34.33 Resize file [fs.op.resize_file]

void resize_file(const path& p, uintmax_t new_size); void resize_file(const path& p, uintmax_t new_size, error_code& ec) noexcept;

Postconditions: file_­size(p) == new_­size.

Remarks: Achieves its postconditions as if by POSIX truncate().

30.10.34.34 Space [fs.op.space]

space_info space(const path& p); space_info 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.

Remarks: The value of member space_­info​::​available is operating system dependent. [Note: available may be less than free. end note]

30.10.34.35 Status [fs.op.status]

file_status 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;

Throws: filesystem_­error. [Note: 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 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: 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:

Remarks: If a symbolic link is encountered during pathname resolution, pathname resolution continues using the contents of the symbolic link.

30.10.34.37 Symlink status [fs.op.symlink_status]

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

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.

Remarks: Pathname resolution terminates if p names a symbolic link.

30.10.34.38 Temporary directory path [fs.op.temp_dir_path]

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

Returns: An unspecifed directory path suitable for temporary files. An error shall be reported if !exists(p) || !is_­directory(p), where p is the path to be returned. The signature with argument ec returns path() if an error occurs.

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

30.10.34.39 Weakly canonical [fs.op.weakly_canonical]

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

Returns: p with symlinks resolved and the result normalized.

Effects: Using status(p) or status(p, ec), respectively, to determine existence, return a path composed by operator/= from the result of calling canonical() without a base argument and 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.

Remarks: Implementations are encouraged to avoid unnecessary normalization such as when canonical has already been called on the entirety of p.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4