std::filesy...ory_iterator(3)
π NAME π
bestie, welcome to the std::filesy...ory_iterator(3) page from the C++ Standard Libary manual. The NAME line is lowkey an echo: std::filesystem::directory_iterator::directory_iterator - std::filesystem::directory_iterator::directory_iterator. Thatβs the constructor page, and itβs giving βI contain multitudesβ energy. π
β¨ SYNOPSIS β¨
All seven overloads are (since C++17), and the labels (1)β(7) match the glow-up list below:
directory_iterator() noexcept; (1) (since C++17)
explicit directory_iterator( const std::filesystem::path& p ); (2) (since C++17)
directory_iterator( const std::filesystem::path& p,
std::filesystem::directory_options options ); (3) (since C++17)
directory_iterator( const std::filesystem::path& p,
std::error_code& ec ); (4) (since C++17)
directory_iterator( const std::filesystem::path& p,
std::filesystem::directory_options options,
std::error_code& ec ); (5) (since C++17)
directory_iterator( const directory_iterator& other ) = default; (6) (since C++17)
directory_iterator( directory_iterator&& other ) = default; (7) (since C++17)
Constructs a new directory iterator. Hereβs the overload tea, one by one:
- (1) Constructs the end iterator. iconic. π«Ά
- (2) Constructs a directory iterator that refers to the first directory entry of a directory identified by
p. Ifprefers to a non-existing file or not a directory, throwsstd::filesystem::filesystem_error. π - (3) Same as (2), but if
std::filesystem::directory_options::skip_permission_deniedis set inoptionsand construction encounters a permissions denied error, constructs the end iterator and does not report an error. no drama, no error report. β¨ - (4) Constructs a directory iterator that refers to the first directory entry of a directory identified by
p. Ifprefers to a non-existing file or not a directory, returns the end iterator and setsec. - (5) Same as (4), but if
std::filesystem::directory_options::skip_permission_deniedis set inoptionsand construction encounters a permissions denied error, constructs the end iterator and does not report an error. - (6) Copy constructor. copy that vibe. π
- (7) Move constructor. move it, move it. πΊ
π PARAMETERS π
pβ path to the filesystem object to which the directory iterator will refer.ecβ out-parameter for error reporting in the non-throwing overloads.optionsβ the set ofBitmaskTypeoptions that control the behavior of the directory iterator.otherβ another directory iterator to use as source to initialize the directory iterator with.
π¨ EXCEPTIONS π¨
Any overload not marked noexcept may throw std::bad_alloc if memory allocation fails. yes, even your fave can get alloc-broke. π
2,3) Throws std::filesystem::filesystem_error on underlying OS API errors, constructed with p as the first path argument and the OS error code as the error code argument.
4,5) Sets a std::error_code& parameter to the OS API error code if an OS API call fails, and executes ec.clear() if no errors occur.
π NOTES π
To iterate over the current directory, construct the iterator as directory_iterator(".") instead of directory_iterator(""). tiny syntax detail, big main character energy. π
π» EXAMPLE π»
This section is incomplete. Reason: no example. literally no example bestie, the page said what it said. π
π©Ή DEFECT REPORTS π©Ή
The following behavior-changing defect reports were applied retroactively to previously published C++ standards. retroactive lore, periodt. π
- DR:
LWG 3013 - Applied to:
C++17 - Behavior as published:
error_codeoverload markednoexceptbut can allocate memory - Correct behavior:
noexceptremoved
ποΈ CATEGORY ποΈ
* Todo no example
π okay thatβs the page! Source/version: http://cppreference.com. Date: 2024.06.10. Footer page: std::filesy...ory_iterator(3). go off, constructor. π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms