Hi
I want to extract the creation datetime a file, use ‘file’ command at ubuntu linux, this datetime of creation is 2022:01:23 16:32:29, which is correct.
somewhere it was suggest os.stat_result.st_birthtime may help. I can’t find it
>>> datetime.date.fromtimestamp(os.stat(f).st_birthtime)*
Traceback (most recent call last):*
File "<stdin>", line 1, in <module>*
AttributeError: 'os.stat_result' object has no attribute 'st_birthtime'
The directory statistics are completely different from the EXIF data inside that file. If you want a way of parsing out that, there are some packages on PyPI that can help.
The st_ctime is not the creation time. Technically, it is “last change
to inode”, which includes chmods, chowns etc i.e. changes to the file’s
OS metadata. Plenty of people think the c means creation, but it does
not.
somewhere it was suggest os.stat_result.st_birthtime may help. I can’t find it
>>> datetime.date.fromtimestamp(os.stat(f).st_birthtime)*
Traceback (most recent call last):*
File "<stdin>", line 1, in <module>*
AttributeError: 'os.stat_result' object has no attribute 'st_birthtime'
Linux (and POSIX) doesn’t specify this field. And it would require
support by the underlying filesystem too.
I gather from this stackoverflow answer that BSD UNIXen have it:
(and MacOS, which is BSD derived). OTOH, an ancient OpenBSD 6.1 system
here (with an equally ancient Python 2.7.13) doesn’t have it.
Anyway, the EXIF data are better - for example, they’ll survive a file
copy, which would otherwise create a young looking file.