Namespaces
Variants

std::filesystem::directory_entry:: is_directory

From cppreference.net
bool is_directory ( ) const ;
(1) (C++17 이후)
bool is_directory ( std:: error_code & ec ) const noexcept ;
(2) (C++17 이후)

가리키는 객체가 디렉토리인지 확인합니다. 효과적으로 다음을 반환합니다:

2) std:: filesystem :: is_directory ( status ( ec ) ) .

목차

매개변수

ec - 비예외 발생 오버로드에서 오류 보고를 위한 출력 매개변수

반환 값

true 만약 참조된 파일시스템 객체가 디렉토리인 경우, false 그 외의 경우.

예외

noexcept 로 표시되지 않은 모든 오버로드는 메모리 할당이 실패할 경우 std::bad_alloc 을(를) throw할 수 있습니다.

1) 기본 OS API 오류 발생 시 std::filesystem::filesystem_error 를 발생시킵니다. 이는 p 를 첫 번째 경로 인수로, OS 오류 코드를 오류 코드 인수로 구성되어 생성됩니다.
2) OS API 호출이 실패할 경우 std:: error_code & 매개변수를 OS API 오류 코드로 설정하고, 오류가 발생하지 않을 경우 ec. clear ( ) 를 실행합니다.

예제

#include <filesystem>
#include <iostream>
#include <string_view>
namespace fs = std::filesystem;
void check_directory(fs::directory_entry const& d, std::string_view rem = "")
{
    std::cout << "is_directory(" << d << "): " << d.is_directory() << rem << '\n';
}
int main()
{
    fs::directory_entry d1(".");
    fs::directory_entry d2("file.txt");
    fs::directory_entry d3("new_dir");
    std::cout << std::boolalpha;
    check_directory(d1);
    check_directory(d2);
    check_directory(d3, " (has not been created yet).");
    std::filesystem::create_directory("new_dir");
    check_directory(d3, " (before refresh).");
    d3.refresh();
    check_directory(d3, " (after refresh).");
}

가능한 출력:

is_directory("."): true
is_directory("file.txt"): false
is_directory("new_dir"): false (has not been created yet).
is_directory("new_dir"): false (before refresh).
is_directory("new_dir"): true (after refresh).

참고 항목

주어진 경로가 디렉터리를 참조하는지 확인합니다
(함수)