std::experimental::filesystem::recursive_directory_iterator:: depth
From cppreference.net
<
cpp
|
experimental
|
fs
|
recursive directory iterator
C++
Experimental
| Technical Specification | ||||
| Filesystem library (filesystem TS) | ||||
| Library fundamentals (library fundamentals TS) | ||||
| Library fundamentals 2 (library fundamentals TS v2) | ||||
| Library fundamentals 3 (library fundamentals TS v3) | ||||
| Extensions for parallelism (parallelism TS) | ||||
| Extensions for parallelism 2 (parallelism TS v2) | ||||
| Extensions for concurrency (concurrency TS) | ||||
| Extensions for concurrency 2 (concurrency TS v2) | ||||
| Concepts (concepts TS) | ||||
| Ranges (ranges TS) | ||||
| Reflection (reflection TS) | ||||
| Mathematical special functions (special functions TR) | ||||
| Experimental Non-TS | ||||
| Pattern Matching | ||||
| Linear Algebra | ||||
| std::execution | ||||
| Contracts | ||||
| 2D Graphics |
Filesystem library
| Classes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| File types | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
recursive_directory_iterator
| Member functions | ||||
|
recursive_directory_iterator::depth
|
||||
| Non-member functions | ||||
|
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"