GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::filesystem::recursive_directory_iterator::depth(3) C++ Standard Libary std::filesystem::recursive_directory_iterator::depth(3)

std::filesystem::recursive_directory_iterator::depth - std::filesystem::recursive_directory_iterator::depth


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.


(none)


Current depth of the directory hierarchy.


Throws nothing.


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::current_path(fs::temp_directory_path());
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");
}


"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"

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.