std::filesystem::file_type

std::filesystem::file_type (파일 유형 상수)

경로가 가리키는 파일·디렉터리의 유형을 나타내는 상수를 정의하는 열거 타입이에요. C++17부터 있어요.

출처: cppreference

본문

<filesystem> 헤더에 정의돼 있어요.

enum class file_type {
    none = /* unspecified */,
    not_found = /* unspecified */,
    regular = /* unspecified */,
    directory = /* unspecified */,
    symlink = /* unspecified */,
    block = /* unspecified */,
    character = /* unspecified */,
    fifo = /* unspecified */,
    socket = /* unspecified */,
    unknown = /* unspecified */,
    /* implementation-defined */
};

file_type은 경로가 가리키는 파일·디렉터리의 유형을 나타내는 상수를 정의해요. 열거자들의 값은 서로 달라요.

상수

  • none — 파일 상태가 아직 평가되지 않았거나, 평가 중 오류가 발생했음을 나타내요.
  • not_found — 파일을 찾지 못했음을 나타내요(오류로 간주하지 않아요).
  • regular — 일반 파일.
  • directory — 디렉터리.
  • symlink — 심볼릭 링크.
  • block — 블록 특수 파일.
  • character — 문자 특수 파일.
  • fifo — FIFO(파이프라고도 함) 파일.
  • socket — 소켓 파일.
  • unknown — 파일은 존재하지만 그 유형을 결정할 수 없어요.
  • implementation-defined — 구현이 지원하는 각 추가 파일 유형에 대한 추가 구현 정의 상수(예: MSVC STL은 NTFS junction에 대해 junction을 정의해요).

예제

#include <cstdio>
#include <cstring>
#include <filesystem>
#include <fstream>
#include <iostream>
namespace fs = std::filesystem;

// fs::file_type 가 switch(s.type()) { case fs::file_type::regular: ... } 식으로 쓰임

더 알아보기 (Learn more)

cppreference