views:

79

answers:

4

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.

A: 

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.

Richard Cook
+3  A: 

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);
Daniel
A: 

Another, slightly simpler code snippet for Windows.

Ben L
A: 

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.

usta