std::experimental::filesystem::recursive_directory_iterator::depth (3) - Linux Manuals
std::experimental::filesystem::recursive_directory_iterator::depth: std::experimental::filesystem::recursive_directory_iterator::depth
Command to display std::experimental::filesystem::recursive_directory_iterator::depth
manual in Linux: $ man 3 std::experimental::filesystem::recursive_directory_iterator::depth
NAME
std::experimental::filesystem::recursive_directory_iterator::depth - std::experimental::filesystem::recursive_directory_iterator::depth
Synopsis
int depth() const; (filesystem TS)
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 <experimental/filesystem>
namespace fs = std::experimental::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::experimental::filesystem::recursive_directory_iterator::depth
- std::experimental::filesystem::recursive_directory_iterator::disable_recursion_pending (3) - std::experimental::filesystem::recursive_directory_iterator::disable_recursion_pending
- std::experimental::filesystem::recursive_directory_iterator::operator*, (3) - std::experimental::filesystem::recursive_directory_iterator::operator*,
- std::experimental::filesystem::recursive_directory_iterator::operator*,std::experimental::filesystem::recursive_directory_iterator::operator-> (3) - std::experimental::filesystem::recursive_directory_iterator::operator*,std::experimental::filesystem::recursive_directory_iterator::operator->
- std::experimental::filesystem::recursive_directory_iterator::operator++,increment (3) - std::experimental::filesystem::recursive_directory_iterator::operator++,increment
- std::experimental::filesystem::recursive_directory_iterator::operator= (3) - std::experimental::filesystem::recursive_directory_iterator::operator=
- std::experimental::filesystem::recursive_directory_iterator::options (3) - std::experimental::filesystem::recursive_directory_iterator::options
- std::experimental::filesystem::recursive_directory_iterator::pop (3) - std::experimental::filesystem::recursive_directory_iterator::pop
- std::experimental::filesystem::recursive_directory_iterator::recursion_pending (3) - std::experimental::filesystem::recursive_directory_iterator::recursion_pending
- std::experimental::filesystem::recursive_directory_iterator::recursive_directory_iterator (3) - std::experimental::filesystem::recursive_directory_iterator::recursive_directory_iterator
- std::experimental::filesystem::recursive_directory_iterator (3) - std::experimental::filesystem::recursive_directory_iterator
- std::experimental::filesystem::read_symlink (3) - std::experimental::filesystem::read_symlink
- std::experimental::filesystem::remove,std::experimental::filesystem::remove_all (3) - std::experimental::filesystem::remove,std::experimental::filesystem::remove_all
- std::experimental::filesystem::rename (3) - std::experimental::filesystem::rename
- std::experimental::filesystem::resize_file (3) - std::experimental::filesystem::resize_file
- std::experimental::filesystem::absolute,std::experimental::filesystem::system_complete (3) - std::experimental::filesystem::absolute,std::experimental::filesystem::system_complete
- std::experimental::filesystem::begin(directory_iterator), (3) - std::experimental::filesystem::begin(directory_iterator),
- std::experimental::filesystem::begin(directory_iterator),std::experimental::filesystem::end(directory_iterator) (3) - std::experimental::filesystem::begin(directory_iterator),std::experimental::filesystem::end(directory_iterator)
- std::experimental::filesystem::begin(recursive_directory_iterator), (3) - std::experimental::filesystem::begin(recursive_directory_iterator),
- std::experimental::filesystem::begin(recursive_directory_iterator),std::experimental::filesystem::end(recursive_directory_iterator) (3) - std::experimental::filesystem::begin(recursive_directory_iterator),std::experimental::filesystem::end(recursive_directory_iterator)
- std::experimental::filesystem::canonical (3) - std::experimental::filesystem::canonical
- std::experimental::filesystem::copy (3) - std::experimental::filesystem::copy
- std::experimental::filesystem::copy_file (3) - std::experimental::filesystem::copy_file
- std::experimental::filesystem::copy_options (3) - std::experimental::filesystem::copy_options
- std::experimental::filesystem::copy_symlink (3) - std::experimental::filesystem::copy_symlink
- std::experimental::filesystem::create_directory, (3) - std::experimental::filesystem::create_directory,
- std::experimental::filesystem::create_directory,std::experimental::filesystem::create_directories (3) - std::experimental::filesystem::create_directory,std::experimental::filesystem::create_directories
- std::experimental::filesystem::create_hard_link (3) - std::experimental::filesystem::create_hard_link
- std::experimental::filesystem::create_symlink, (3) - std::experimental::filesystem::create_symlink,
- std::experimental::filesystem::create_symlink,std::experimental::filesystem::create_directory_symlink (3) - std::experimental::filesystem::create_symlink,std::experimental::filesystem::create_directory_symlink
- std::experimental::filesystem::current_path (3) - std::experimental::filesystem::current_path
- std::experimental::filesystem::directory_entry (3) - std::experimental::filesystem::directory_entry
- std::experimental::filesystem::directory_entry::assign (3) - std::experimental::filesystem::directory_entry::assign
- std::experimental::filesystem::directory_entry::directory_entry (3) - std::experimental::filesystem::directory_entry::directory_entry
- std::experimental::filesystem::directory_entry::operator= (3) - std::experimental::filesystem::directory_entry::operator=
- std::experimental::filesystem::directory_entry::operator==,!=,<,<=,>,>= (3) - std::experimental::filesystem::directory_entry::operator==,!=,<,<=,>,>=