I need to modify the 'created' (if exists), 'modified' and 'accessed' timestamps of a file. Ideally this would be a platform-independent solution.
I've looked around the boost libraries but I can't see anything relevant. The nearest I've found to something relevant is this for Windows.
Can anyone help? Thanks.
Unfortunately, this isn't possible. You can view certain and change certain file attributes in File Explorer, but you can't change the last viewed, edited, or modified dates.
You can modify the date created by copying a file. The file's created date becomes the modified date and the current date (when the file is copied) becomes the created date. You can copy a file on your PC to check.
The default behavior of touch command is to change all three timestamps associated with a file to the current system time.
I've never used them but i guess that you are looking for the attribute functions:
http://www.boost.org/doc/libs/1_44_0/libs/filesystem/v2/doc/reference.html#Attribute-functions
There are also functions for the last modification:
template <class Path> std::time_t last_write_time(const Path& p);
template <class Path> void last_write_time(const Path& p, const std::time_t new_time);
Another, slightly simpler code snippet for Windows.
Use the utime
function and utimbuf
struct. The method is available in Windows but is named with a leading underscore as _utime
.
Update: utime
only allows you to change the access and modification times (via utimbuf
's actime
and modtime
fields). This is most likely because many Unix-style file systems do not record the creation time anywhere.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With