Edit

<experimental/filesystem> directory_entry class

Important

This article describes the prestandard std::experimental::filesystem implementation of directory_entry. This implementation is based on the File System Technical Specification, found in ISO/IEC JTC 1/SC 22/WG 21 N4100. It isn't std::filesystem, and it isn't compatible with the C++17 std::filesystem implementation. The experimental implementation was removed starting in MSVC toolset version 14.51. For the current C++17 std::filesystem version, see directory_entry class.

Describes an object that is returned by *X, where X is a directory_iterator or a recursive_directory_iterator.

Syntax

class directory_entry;

Remarks

The class stores an object of type path. The stored path can be an instance of the path class or of a type that is derived from path. It also stores two file_type values. One value represents the status of the stored file name. The other represents the symbolic link status of the file name.

Constructors

Constructor Description
directory_entry The defaulted constructors behave as expected. The fourth constructor initializes mypath to pval, mystat to stat_arg, and mysymstat to symstat_arg.

Member functions

Member function Description
assign The member function assigns pval to mypath, stat to mystat, and symstat to mysymstat.
path The member function returns mypath.
replace_filename The member function replaces mypath with mypath.parent_path() / pval, mystat with stat_arg, and mysymstat with symstat_arg
status Both member functions return mystat possibly first altered.
symlink_status Both member functions return mysymstat possibly first altered.

Operators

Operator Description
operator!= Returns !(*this == right).
operator= The defaulted member assignment operators behave as expected.
operator== Returns mypath == right.mypath.
operator< Returns mypath < right.mypath.
operator<= Returns !(right < *this).
operator> Returns right < *this.
operator>= Returns !(*this < right).
operator const path_type& Returns mypath.

Requirements

Header: <experimental/filesystem>

Namespace: std::experimental::filesystem

assign

The member function assigns pval to mypath, stat_arg to mystat, and symstat_arg to mysymstat.

void assign(const std::experimental::filesystem::path& pval,
    file_status stat_arg = file_status(),
    file_status symstat_arg = file_status());

Parameters

pval
The stored file name path.

stat_arg
The status of the stored file name.

symstat_arg
The symbolic link status of the stored file name.

directory_entry

The defaulted constructors behave as expected. The fourth constructor initializes mypath to pval, mystat to stat_arg, and mysymstat to symstat_arg.

directory_entry() = default;
directory_entry(const directory_entry&) = default;
directory_entry(directory_entry&&) noexcept = default;
explicit directory_entry(const std::experimental::filesystem::path& pval,
    file_status stat_arg = file_status(),
    file_status symstat_arg = file_status());

Parameters

pval
The stored file name path.

stat_arg
The status of the stored file name.

symstat_arg
The symbolic link status of the stored file name.

operator!=

The member function returns !(*this == right).

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

Parameters

right
The directory_entry being compared to the directory_entry.

operator=

The defaulted member assignment operators behave as expected.

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

Parameters

right
The directory_entry being copied into the directory_entry.

operator==

The member function returns mypath == right.mypath.

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

Parameters

right
The directory_entry being compared to the directory_entry.

operator<

The member function returns mypath < right.mypath.

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

Parameters

right
The directory_entry being compared to the directory_entry.

operator<=

The member function returns !(right < *this).

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

Parameters

right
The directory_entry being compared to the directory_entry.

operator>

The member function returns right < *this.

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

Parameters

right
The directory_entry being compared to the directory_entry.

operator>=

The member function returns !(*this < right).

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

Parameters

right
The directory_entry being compared to the directory_entry.

operator const path_type&

The member operator returns mypath.

operator const std::experimental::filesystem::path&() const;

path

The member function returns mypath.

const std::experimental::filesystem::path& path() const noexcept;

replace_filename

The member function replaces mypath with mypath.parent_path() / pval, mystat with stat_arg, and mysymstat with symstat_arg

void replace_filename(
    const std::experimental::filesystem::path& pval,
    file_status stat_arg = file_status(),
    file_status symstat_arg = file_status());

Parameters

pval
The stored file name path.

stat_arg
The status of the stored file name.

symstat_arg
The symbolic link status of the stored file name.

status

Both member functions return mystat possibly first altered as follows:

  1. If status_known(mystat) then do nothing.

  2. Otherwise, if !status_known(mysymstat) && !is_symlink(mysymstat) then mystat = mysymstat.

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

Parameters

ec
The status error code.

Both member functions return mysymstat possibly first altered as follows: If status_known(mysymstat) then do nothing. Otherwise, mysymstat = symlink_status(mypval).

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

Parameters

ec
The status error code.

See also

<experimental/filesystem>
path class