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 为结束迭代器,则行为未定义。
目录 |
参数
(无)
返回值
当前目录层次结构的深度。
异常
不抛出任何异常。
示例
本示例使用迭代深度计算目录树打印输出的缩进。
运行此代码
#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"