Skip to main content

Posts

Showing posts from November, 2011

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.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. 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; }