[fs.rec.dir.itr.members]

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

## 31.12 File systems [[filesystems]](filesystems#fs.rec.dir.itr.members)

### 31.12.12 Class recursive_directory_iterator [[fs.class.rec.dir.itr]](fs.class.rec.dir.itr#fs.rec.dir.itr.members)

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

[ð](#lib:recursive_directory_iterator,constructor)

`recursive_directory_iterator() noexcept;
`

[1](#1)

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

*Effects*: Constructs the end iterator[.](#1.sentence-1)

[ð](#lib:recursive_directory_iterator,constructor_)

`explicit recursive_directory_iterator(const path& p);
recursive_directory_iterator(const path& p, directory_options options);
recursive_directory_iterator(const path& p, directory_options options, error_code& ec);
recursive_directory_iterator(const path& p, error_code& ec);
`

[2](#2)

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

*Effects*: Constructs an iterator representing the first
entry in the directory to which p resolves, if any; otherwise, the end iterator[.](#2.sentence-1)

However, if(options & directory_options::skip_permission_denied) != directory_options::none and construction encounters an error indicating
that permission to access p is denied, constructs the end iterator
and does not report an error[.](#2.sentence-2)

[3](#3)

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

*Postconditions*: options() == options for the signatures with adirectory_options argument, otherwise options() == directory_options​::​none[.](#3.sentence-1)

[4](#4)

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

*Throws*: As specified in [[fs.err.report]](fs.err.report "31.12.5 Error reporting")[.](#4.sentence-1)

[5](#5)

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

[*Note [1](#note-1)*:

Use recursive_directory_iterator(".") rather than recursive_directory_iterator("") to iterate over the current directory[.](#5.sentence-1)

â *end note*]

[6](#6)

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

[*Note [2](#note-2)*:

By default, recursive_directory_iterator does not
follow directory symlinks[.](#6.sentence-1)

To follow directory symlinks, specify options asdirectory_options​::​follow_directory_symlink[.](#6.sentence-2)

â *end note*]

[ð](#lib:recursive_directory_iterator,constructor__)

`recursive_directory_iterator(const recursive_directory_iterator& rhs);
`

[7](#7)

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

*Postconditions*: 

- [(7.1)](#7.1)

options() == rhs.options()

- [(7.2)](#7.2)

depth() == rhs.depth()

- [(7.3)](#7.3)

recursion_pending() == rhs.recursion_pending()

[ð](#lib:recursive_directory_iterator,constructor___)

`recursive_directory_iterator(recursive_directory_iterator&& rhs) noexcept;
`

[8](#8)

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

*Postconditions*: options(), depth(),
 and recursion_pending() have the values that rhs.options(), rhs.depth(), and rhs.recursion_pending(), respectively, had before the function call[.](#8.sentence-1)

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

`recursive_directory_iterator& operator=(const recursive_directory_iterator& rhs);
`

[9](#9)

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

*Effects*: If *this and rhs are the same
 object, the member has no effect[.](#9.sentence-1)

[10](#10)

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

*Postconditions*: 

- [(10.1)](#10.1)

options() == rhs.options()

- [(10.2)](#10.2)

depth() == rhs.depth()

- [(10.3)](#10.3)

recursion_pending() == rhs.recursion_pending()

[11](#11)

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

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

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

`recursive_directory_iterator& operator=(recursive_directory_iterator&& rhs) noexcept;
`

[12](#12)

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

*Effects*: If *this and rhs are the same
object, the member has no effect[.](#12.sentence-1)

[13](#13)

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

*Postconditions*: options(), depth(),
and recursion_pending() have the values that rhs.options(),rhs.depth(), and rhs.recursion_pending(), respectively, had before the function call[.](#13.sentence-1)

[14](#14)

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

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

[ð](#lib:options,recursive_directory_iterator)

`directory_options options() const;
`

[15](#15)

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

*Returns*: The value of the argument passed to the constructor for theoptions parameter, if present, otherwisedirectory_options​::​none[.](#15.sentence-1)

[16](#16)

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

*Throws*: Nothing[.](#16.sentence-1)

[ð](#lib:depth,recursive_directory_iterator)

`int depth() const;
`

[17](#17)

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

*Returns*: The current depth of the directory tree being traversed[.](#17.sentence-1)

[*Note [3](#note-3)*:

The initial directory is depth 0, its immediate subdirectories are depth 1,
 and so forth[.](#17.sentence-2)

â *end note*]

[18](#18)

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

*Throws*: Nothing[.](#18.sentence-1)

[ð](#lib:recursion_pending,recursive_directory_iterator)

`bool recursion_pending() const;
`

[19](#19)

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

*Returns*: true if disable_recursion_pending() has not been called subsequent to the prior construction or increment
 operation, otherwise false[.](#19.sentence-1)

[20](#20)

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

*Throws*: Nothing[.](#20.sentence-1)

[ð](#lib:increment,recursive_directory_iterator)

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

[21](#21)

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

*Effects*: As specified for the prefix increment operation of[Input iterators](input.iterators "24.3.5.3 Input iterators [input.iterators]"),
except that:

- [(21.1)](#21.1)

If there are no more entries at the current depth, then if depth() != 0 iteration over the parent directory resumes; otherwise *this = recursive_directory_iterator().

- [(21.2)](#21.2)

Otherwise ifrecursion_pending() && is_directory((*this)->status()) &&(!is_symlink((*this)->symlink_status()) ||(options() & directory_options::follow_directory_symlink) != directory_options::none) then either directory (*this)->path() is recursively iterated into or,
if(options() & directory_options::skip_permission_denied) != directory_options::none and an error occurs indicating that permission to access directory (*this)->path() is denied,
then directory (*this)->path() is
treated as an empty directory and no error is reported.

[22](#22)

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

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

[23](#23)

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

*Throws*: As specified in [[fs.err.report]](fs.err.report "31.12.5 Error reporting")[.](#23.sentence-1)

[ð](#lib:pop,recursive_directory_iterator)

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

[24](#24)

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

*Effects*: If depth() == 0, set *this to recursive_directory_iterator()[.](#24.sentence-1)

Otherwise, cease iteration of the directory currently being
 iterated over, and continue iteration over the parent directory[.](#24.sentence-2)

[25](#25)

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

*Throws*: As specified in [[fs.err.report]](fs.err.report "31.12.5 Error reporting")[.](#25.sentence-1)

[26](#26)

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

*Remarks*: Any copies of the previous value of *this are no longer required
to be dereferenceable nor to be in the domain of ==[.](#26.sentence-1)

[ð](#lib:disable_recursion_pending,recursive_directory_iterator)

`void disable_recursion_pending();
`

[27](#27)

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

*Postconditions*: recursion_pending() == false[.](#27.sentence-1)

[28](#28)

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

[*Note [4](#note-4)*:

disable_recursion_pending() is used to prevent
 unwanted recursion into a directory[.](#28.sentence-1)

â *end note*]
