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

아래는 파일의 크기와 최근 수정 날짜를 가져오는 간단한 예제입니다.

#include <iostream>
#include <filesystem>
#include <chrono>
#include <string>

int main() {
    std::string filepath = "example.txt";

    if (std::filesystem::exists(filepath)) {
        std::cout << "File size: " << std::filesystem::file_size(filepath) << " bytes\n";
        auto ftime = std::filesystem::last_write_time(filepath);
        std::time_t cftime = decltype(ftime)::clock::to_time_t(ftime);
        std::cout << "Last modified: " << std::ctime(&cftime);
    } else {
        std::cout << "File not found\n";
    }
    return 0;
}

위 예제에서는 <filesystem> 헤더 파일을 사용하여 파일 시스템 라이브러리를 포함시키고, std::filesystem::exists 함수와 std::filesystem::file_size 함수를 통해 파일의 존재 여부와 크기를 확인하고, std::filesystem::last_write_time 함수를 사용하여 파일의 최근 수정 시간을 가져왔습니다.

이러한 방식으로 필요한 파일 및 디렉토리 프로퍼티를 확인할 수 있습니다.