Namespaces
Variants

std::filesystem::recursive_directory_iterator:: disable_recursion_pending

From cppreference.net
void disable_recursion_pending ( ) ;
(C++17부터)

현재 참조 중인 하위 디렉터리가 있는 경우, 해당 디렉터리에 대한 재귀를 비활성화합니다.

이 호출은 반복자의 보류 중인 재귀 플래그를 수정하여 다음에 increment 가 호출될 때, 반복자가 현재 방문되지 않은 하위 디렉토리를 참조하고 있는 경우에도 현재 디렉토리 내에서 진행되도록 합니다.

보류 중인 재귀 플래그의 상태는 recursion_pending() 로 조회할 수 있으며, 이 호출 이후에는 false 가 됩니다. 이 값은 increment 이후에 다시 true 로 재설정되며, 초기값 또한 true 입니다.

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

목차

매개변수

(없음)

반환값

(없음)

예외

구현 정의 예외를 던질 수 있습니다.

예제

#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <string>
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");
    std::system("tree sandbox");
    for (auto i = fs::recursive_directory_iterator("sandbox");
         i != fs::recursive_directory_iterator();
         ++i)
    {
        std::cout << std::string(i.depth() * 2, ' ') << *i;
        if (fs::is_symlink(i->symlink_status()))
            std::cout << " -> " << fs::read_symlink(*i);
        std::cout << '\n';
        // "b" 디렉토리로는 내려가지 않음
        if (i->path().filename() == "b")
            i.disable_recursion_pending();
    }
    fs::remove_all("sandbox");
}

가능한 출력:

sandbox
├── a
│   └── b
│       ├── c
│       ├── d
│       │   └── e
│       └── file1.txt
└── syma -> a
"sandbox/a"
  "sandbox/a/b"
"sandbox/syma" -> "a"

참고 항목

현재 디렉터리에 대해 재귀가 비활성화되었는지 확인합니다
(public member function)
다음 항목으로 이동합니다
(public member function)