std::filesystem::directory_entry:: last_write_time
From cppreference.net
<
cpp
|
filesystem
|
directory entry
|
std::
filesystem
::
file_time_type
last_write_time
(
)
const
;
|
(1) | (C++17 이후) |
|
std::
filesystem
::
file_time_type
last_write_time
(
std::
error_code
&
ec
)
const
noexcept
;
|
(2) | (C++17 이후) |
마지막 수정 시간이 이
directory_entry
에 캐시되어 있으면 캐시된 값을 반환합니다. 그렇지 않으면 다음을 반환합니다:
1)
std::
filesystem
::
last_write_time
(
path
(
)
)
.
2)
std::
filesystem
::
last_write_time
(
path
(
)
, ec
)
.
목차 |
매개변수
| ec | - | 비예외 발생 오버로드에서 오류 보고를 위한 출력 매개변수 |
반환값
참조된 파일 시스템 객체의 마지막 수정 시간.
예외
noexcept
로 표시되지 않은 모든 오버로드는 메모리 할당이 실패할 경우
std::bad_alloc
을 throw할 수 있습니다.
1)
기본 OS API 오류 발생 시
std::filesystem::filesystem_error
를 throw하며,
p
를 첫 번째 경로 인수로, OS 오류 코드를 에러 코드 인수로 사용하여 구성됩니다.
2)
OS API 호출이 실패할 경우
std::
error_code
&
매개변수를 OS API 오류 코드로 설정하고, 오류가 발생하지 않을 경우
ec.
clear
(
)
를 실행합니다.
예제
이 코드 실행
#include <chrono> #include <ctime> #include <filesystem> #include <format> #include <iostream> #include <string> std::string to_string(const std::filesystem::file_time_type& ftime) { #if __cpp_lib_format return std::format("{:%c}", ftime); #else std::time_t cftime = std::chrono::system_clock::to_time_t( std::chrono::file_clock::to_sys(ftime)); std::string str = std::asctime(std::localtime(&cftime)); str.pop_back(); // rm the trailing '\n' put by `asctime` return str; #endif } int main() { auto dir = std::filesystem::current_path(); using Entry = std::filesystem::directory_entry; for (Entry const& entry : std::filesystem::directory_iterator(dir)) std::cout << to_string(entry.last_write_time()) << " : " << entry.path().filename() << '\n'; }
가능한 출력:
Wed Sep 6 13:37:13.960314156 2023 : "main.cpp" Wed Sep 6 13:37:42.690271828 2023 : "a.out"
참고 항목
|
(C++17)
|
마지막 데이터 수정 시간을 가져오거나 설정합니다
(함수) |