|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
The age of a file
I python on a unix OS how can you find out the age of a file? I'm sorry I can't show you and example code because I don't even know where to start
|
|
#2
|
|||
|
|||
|
Code:
import os
import stat
import time
time.ctime(os.stat('file')[stat.ST_CTIME])
|
|
#3
|
|||
|
|||
|
percivall is right, but the object returned from os.stat now has attributes to make accessing the data easier. You can get the time of creation with
Code:
os.stat('path/to/file').st_ctime
To get the age of the file (in seconds) you need subtract this from the current time. Code:
import time
import os
age = time.time() - os.stat('path/to/file').st_ctime
Dave - The Developers' Coach |
|
#4
|
||||
|
||||
|
Thank you, the two of you have been a great help
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > The age of a file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|