Namespaces
Variants

std::experimental::filesystem:: last_write_time

From cppreference.net
헤더 파일에 정의됨 <experimental/filesystem>
file_time_type last_write_time ( const path & p ) ;
file_time_type last_write_time ( const path & p, error_code & ec )
(1) (filesystem TS)
void last_write_time ( const path & p, file_time_type new_time ) ;
void last_write_time ( const path & p, file_time_type new_time, error_code & ec ) ;
(2) (filesystem TS)
1) p 의 마지막 수정 시간을 반환하며, POSIX stat 의 멤버 st_mtime 에 접근하는 것처럼 결정됩니다(심볼릭 링크는 따름). 예외를 던지지 않는 오버로드는 오류 발생 시 file_time_type :: min ( ) 를 반환합니다.
2) p 의 최종 수정 시간을 변경합니다. POSIX futimens 와 유사하게 동작합니다(심볼릭 링크는 따라갑니다).

목차

매개변수

p - 검사하거나 수정할 경로
new_time - 새로운 수정 시간
ec - 비예외 발생 오버로드에서 오류 보고를 위한 출력 매개변수

반환값

1) p 의 마지막 수정 시간.
2) (없음)

예외

The overload that does not take an error_code & parameter throws filesystem_error on underlying OS API errors, constructed with p as the first argument and the OS error code as the error code argument. std:: bad_alloc may be thrown if memory allocation fails. The overload taking an error_code & parameter sets it to the OS API error code if an OS API call fails, and executes ec. clear ( ) if no errors occur. This overload has
noexcept 명세:
noexcept

참고 사항

쓰기 시간을 설정한 직후에 (1) 에서 반환되는 값이 (2) 에 인수로 전달된 값과 동일하다는 것이 보장되지 않습니다. 파일 시스템의 시간이 file_time_type 보다 더 세분화되어 있을 수 있기 때문입니다.

예제

#include <chrono>
#include <experimental/filesystem>
#include <fstream>
#include <iomanip>
#include <iostream>
namespace fs = std::experimental::filesystem;
using namespace std::chrono_literals;
int main()
{
    fs::path p = fs::current_path() / "example.bin";
    std::ofstream(p.c_str()).put('a'); // 파일 생성
    auto ftime = fs::last_write_time(p);
    std::time_t cftime = decltype(ftime)::clock::to_time_t(ftime); // system_clock 가정
    std::cout << "File write time is " << std::asctime(std::localtime(&cftime)) << '\n';
    fs::last_write_time(p, ftime + 1h); // 파일 수정 시간을 1시간 미래로 이동
    ftime = fs::last_write_time(p); // 파일시스템에서 다시 읽기
    cftime = decltype(ftime)::clock::to_time_t(ftime);
    std::cout << "File write time is " << std::asctime(std::localtime(&cftime)) << '\n';
    fs::remove(p);
}

가능한 출력:

File write time is Tue Mar 31 19:47:04 2015
File write time is Tue Mar 31 20:47:04 2015

참고 항목

파일 시간 값을 나타냄
(typedef)