tags:

views:

302

answers:

2

os.stat returns st_mtime and st_ctime attributes, the modification time is st_mtime and st_ctime "change time" on POSIX. is there any function that return the creation time of a file using python and under Linux?

+3  A: 

You probably can't.

TokenMacGuy
mezgani
In general, UNIX filesystems do not store creation time at all -- there's no method for retrieving data that was never written to disk in the first place.
ephemient
+1  A: 

try:

st_birthtime

It isnt' guaranteed to be available on all systems though. From the docs:

On some Unix systems (such as Linux), the following attributes may also be available: st_blocks (number of blocks allocated for file), st_blksize (filesystem blocksize), st_rdev (type of device if an inode device). st_flags (user defined flags for file).

On other Unix systems (such as FreeBSD), the following attributes may be available (but may be only filled out if root tries to use them): st_gen (file generation number), st_birthtime (time of file creation).

http://docs.python.org/library/os.html

Jon