std::filesystem::recursive_directory_iterator::depth (3) - Linux Manuals
std::filesystem::recursive_directory_iterator::depth: std::filesystem::recursive_directory_iterator::depth
Command to display std::filesystem::recursive_directory_iterator::depth
manual in Linux: $ man 3 std::filesystem::recursive_directory_iterator::depth
NAME
std::filesystem::recursive_directory_iterator::depth - std::filesystem::recursive_directory_iterator::depth
Synopsis
int depth() const; (since C++17)
Returns the number of directories from the starting directory to the currently iterated directory, i.e. the current depth of the directory hierarchy.
The starting directory has depth of 0, its subdirectories have depth 1, etc.
The behavior is undefined if *this is the end iterator.
Parameters
(none)
Return value
Current depth of the directory hierarchy.
Exceptions
(none)
Example
this example uses iteration depth to calculate the indentation of a directory tree printout
// Run this code
#include <fstream>
#include <iostream>
#include <string>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
fs::create_directories("sandbox/a/b/c");
fs::create_directories("sandbox/a/b/d/e");
std::ofstream("sandbox/a/b/file1.txt");
fs::create_symlink("a", "sandbox/syma");
for(auto i = fs::recursive_directory_iterator("sandbox");
i != fs::recursive_directory_iterator();
++i ) {
std::cout << std::string(i.depth(), ' ') << *i;
if(fs::is_symlink(i->symlink_status()))
std::cout << " -> " << fs::read_symlink(*i);
std::cout << '\n';
}
fs::remove_all("sandbox");
}
Output:
"sandbox/a"
"sandbox/a/b"
"sandbox/a/b/c"
"sandbox/a/b/d"
"sandbox/a/b/d/e"
"sandbox/a/b/file1.txt"
"sandbox/syma" -> "a"
Pages related to std::filesystem::recursive_directory_iterator::depth
- std::filesystem::recursive_directory_iterator::disable_recursion_pending (3) - std::filesystem::recursive_directory_iterator::disable_recursion_pending
- std::filesystem::recursive_directory_iterator::operator*,std::filesystem::recursive_directory_iterator::operator-> (3) - std::filesystem::recursive_directory_iterator::operator*,std::filesystem::recursive_directory_iterator::operator->
- std::filesystem::recursive_directory_iterator::operator++, (3) - std::filesystem::recursive_directory_iterator::operator++,
- std::filesystem::recursive_directory_iterator::operator++,std::filesystem::recursive_directory_iterator::increment (3) - std::filesystem::recursive_directory_iterator::operator++,std::filesystem::recursive_directory_iterator::increment
- std::filesystem::recursive_directory_iterator::operator= (3) - std::filesystem::recursive_directory_iterator::operator=
- std::filesystem::recursive_directory_iterator::options (3) - std::filesystem::recursive_directory_iterator::options
- std::filesystem::recursive_directory_iterator::pop (3) - std::filesystem::recursive_directory_iterator::pop
- std::filesystem::recursive_directory_iterator::recursion_pending (3) - std::filesystem::recursive_directory_iterator::recursion_pending
- std::filesystem::recursive_directory_iterator::recursive_directory_iterator (3) - std::filesystem::recursive_directory_iterator::recursive_directory_iterator
- std::filesystem::recursive_directory_iterator (3) - std::filesystem::recursive_directory_iterator
- std::filesystem::read_symlink (3) - std::filesystem::read_symlink
- std::filesystem::relative,std::filesystem::proximate (3) - std::filesystem::relative,std::filesystem::proximate
- std::filesystem::remove,std::filesystem::remove_all (3) - std::filesystem::remove,std::filesystem::remove_all
- std::filesystem::rename (3) - std::filesystem::rename
- std::filesystem::resize_file (3) - std::filesystem::resize_file
- std::filesystem::absolute (3) - std::filesystem::absolute
- std::filesystem::begin(directory_iterator),std::filesystem::end(directory_iterator) (3) - std::filesystem::begin(directory_iterator),std::filesystem::end(directory_iterator)
- std::filesystem::begin(recursive_directory_iterator), (3) - std::filesystem::begin(recursive_directory_iterator),
- std::filesystem::begin(recursive_directory_iterator),std::filesystem::end(recursive_directory_iterator) (3) - std::filesystem::begin(recursive_directory_iterator),std::filesystem::end(recursive_directory_iterator)
- std::filesystem::canonical,std::filesystem::weakly_canonical (3) - std::filesystem::canonical,std::filesystem::weakly_canonical
- std::filesystem::copy (3) - std::filesystem::copy