Reputation: 7068
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.
Upvotes: 5
Views: 8320
Reputation: 6869
Not all popular filesystems support 'created' and 'accessed' timestamps: http://en.wikipedia.org/wiki/Comparison_of_file_systems#Metadata
Windows filesystems do, but it might not be a good idea to depend on them now if you need portability. Looking at that table I get an impression that there is a trend to add support for them in newer filesystems though.
Upvotes: 0
Reputation: 33089
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.
Upvotes: 2
Reputation: 3063
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);
Upvotes: 7