[c++] 파일 및 디렉토리 경로 확인하기

C++17에서는 <filesystem> 라이브러리가 도입되어 파일 및 디렉토리 관리를 쉽게 할 수 있습니다. 이 라이브러리를 사용하여 파일 및 디렉토리의 존재 여부, 경로 확인, 파일 크기 등을 확인할 수 있습니다.

아래는 C++17에서 <filesystem> 라이브러리를 사용하여 파일 및 디렉토리 경로를 확인하는 방법의 예시입니다.

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

int main() {
    fs::path pathToShow("path_to_file_or_directory");
    if (fs::exists(pathToShow)) {
        if (fs::is_regular_file(pathToShow)) {
            std::cout << pathToShow << " is a regular file" << std::endl;
        } else if (fs::is_directory(pathToShow)) {
            std::cout << pathToShow << " is a directory" << std::endl;
        } else {
            std::cout << pathToShow << " exists, but is not a regular file or directory" << std::endl;
        }
    } else {
        std::cout << pathToShow << " does not exist" << std::endl;
    }
    return 0;
}

위 예시에서 path_to_file_or_directory 부분에는 확인하고자 하는 실제 파일 또는 디렉토리의 경로가 들어갑니다. 이 코드는 해당 경로가 존재하는지 여부를 확인하고, 파일인지 디렉토리인지를 판별하여 출력하는 간단한 예시입니다.

이제, 위 코드를 컴파일하고 실행함으로써 C++로 파일 및 디렉토리의 경로를 확인할 수 있습니다.