Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 28th, 2004, 10:22 AM
the_aimbot's Avatar
the_aimbot the_aimbot is offline
PHP ninja
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Melbourne, Australia
Posts: 20 the_aimbot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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

Reply With Quote
  #2  
Old May 28th, 2004, 11:33 AM
percivall percivall is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 133 percivall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Code:
import os
import stat
import time

time.ctime(os.stat('file')[stat.ST_CTIME])

Reply With Quote
  #3  
Old May 28th, 2004, 11:40 AM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,254 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 8 h 9 m
Reputation Power: 265
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

Reply With Quote
  #4  
Old May 29th, 2004, 12:49 AM
the_aimbot's Avatar
the_aimbot the_aimbot is offline
PHP ninja
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Melbourne, Australia
Posts: 20 the_aimbot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thank you, the two of you have been a great help

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > The age of a file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT