#1
  1. PHP ninja
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Melbourne, Australia
    Posts
    20
    Rep Power
    0

    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. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    133
    Rep Power
    12
    Code:
    import os
    import stat
    import time
    
    time.ctime(os.stat('file')[stat.ST_CTIME])
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    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
  6. #4
  7. PHP ninja
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Melbourne, Australia
    Posts
    20
    Rep Power
    0
    Thank you, the two of you have been a great help

IMN logo majestic logo threadwatch logo seochat tools logo