Skip to content

Instantly share code, notes, and snippets.

@kghose
Created November 20, 2011 20:34
Show Gist options
  • Save kghose/1380855 to your computer and use it in GitHub Desktop.
Save kghose/1380855 to your computer and use it in GitHub Desktop.
How to get file creation time on Mac OS X (64 bit)
/*
* QFileInfo.created() on POSIX systems (like Mac OS X) returns the last modified time[1].
* This is annoying because on Mac OS X you know the system (e.g. finder) has access to the actual creation time.
* Turns out that BSD systems (like Mac OS X) have an extension to sys/stat.h that contains the file creation time[2].
[1]: http://doc.qt.nokia.com/latest/qfileinfo.html#created
[2]: http://developer.apple.com/library/IOS/#documentation/System/Conceptual/ManPages_iPhoneOS/man2/stat.2.html
The recipe, then is (shown using the QT framework)
*/
#include <QtCore>
#include <sys/stat.h>
int main(int argc, char *argv[])
{
QString fname("/Users/kghose/Sandbox/ChhobiTest/2005/2005_07_10/MVI_0693.AVI");
QDateTime thedatetime;
struct stat64 the_time;
stat64(fname.toStdString().c_str(), &the_time);
thedatetime.setTime_t(the_time.st_birthtimespec.tv_sec);
qDebug() << thedatetime;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment