std::experimental::filesystem:: last_write_time
From cppreference.net
<
cpp
|
experimental
|
fs
|
Definiert im Header
<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)
Gibt den Zeitpunkt der letzten Änderung von
p
zurück, ermittelt wie durch Zugriff auf das Element
st_mtime
des POSIX
stat
(Symlinks werden verfolgt).
Die nicht-werfende Überladung gibt bei Fehlern
file_time_type
::
min
(
)
zurück.
2)
Ändert den Zeitpunkt der letzten Änderung von
p
, wie durch POSIX
futimens
(Symlinks werden verfolgt).
Inhaltsverzeichnis |
Parameter
| p | - | zu untersuchender oder zu modifizierender Pfad |
| new_time | - | neue Änderungszeit |
| ec | - | Ausgabeparameter für Fehlerberichterstattung in der nicht-werfenden Überladung |
Rückgabewert
1)
Der Zeitpunkt der letzten Änderung von
p
.
2)
(keine)
Exceptions
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
Spezifikation:
noexcept
Hinweise
Es ist nicht garantiert, dass unmittelbar nach dem Setzen der Schreibzeit der von
(1)
zurückgegebene Wert derselbe ist wie der, der als Argument an
(2)
übergeben wurde, da die Zeitgranularität des Dateisystems feiner sein kann als
file_time_type
.
Beispiel
Diesen Code ausführen
#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'); // Datei erstellen auto ftime = fs::last_write_time(p); std::time_t cftime = decltype(ftime)::clock::to_time_t(ftime); // Annahme: system_clock std::cout << "File write time is " << std::asctime(std::localtime(&cftime)) << '\n'; fs::last_write_time(p, ftime + 1h); // Schreibzeit der Datei um 1 Stunde in die Zukunft verschieben ftime = fs::last_write_time(p); // Erneut aus dem Dateisystem auslesen cftime = decltype(ftime)::clock::to_time_t(ftime); std::cout << "File write time is " << std::asctime(std::localtime(&cftime)) << '\n'; fs::remove(p); }
Mögliche Ausgabe:
File write time is Tue Mar 31 19:47:04 2015 File write time is Tue Mar 31 20:47:04 2015
Siehe auch
|
repräsentiert Dateizeitwerte
(typedef) |