Namespaces
Variants

std::experimental::filesystem::recursive_directory_iterator:: depth

From cppreference.net
int depth ( ) const ;
(파일시스템 TS)

시작 디렉토리부터 현재 반복 중인 디렉토리까지의 디렉토리 개수를 반환합니다. 즉, 디렉토리 계층 구조의 현재 깊이를 나타냅니다.

시작 디렉토리의 깊이는 0 이며, 그 하위 디렉토리들의 깊이는 1 입니다.

* this 가 end iterator인 경우 동작은 정의되지 않습니다.

목차

매개변수

(없음)

반환값

현재 디렉토리 계층 구조의 깊이입니다.

예외

아무것도 던지지 않습니다.

예제

이 예제는 반복 깊이를 사용하여 디렉토리 트리 출력의 들여쓰기를 계산합니다.

#include <experimental/filesystem>
#include <fstream>
#include <iostream>
#include <string>
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");
}

출력:

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