File Modification Time

Thread Solved

Join Date: Aug 2005
Posts: 1,523
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 168
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

File Modification Time

 
0
  #1
Jun 28th, 2006
Does Python have a module to display when a file has been last modified?

Also, how do you get the file length?
drink her pretty
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,959
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 918
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: File Modification Time

 
0
  #2
Jun 29th, 2006
The functions are contained in module os. Function os.path.getmtime() gives you the last modified time in seconds since the beginning of 1/1/1970 (epoch). You have to do some formatting with module time functions to make it readable for the ordinary mortal.

The size of the file is returned by os.path.getsize() in bytes, convert to kilobytes and format the result.
  1. import os
  2. import time
  3.  
  4. # pick a file you have in the working folder ...
  5. fname = "Texture.py"
  6.  
  7. print "File was last modified (12 hour format):"
  8. print time.strftime("%m/%d/%Y %I:%M:%S %p",time.localtime(os.path.getmtime(fname)))
  9.  
  10. fsize = os.path.getsize(fname)
  11. print "size = %0.1f kb" % float(fsize/1000.0)
  12.  
  13. """
  14. possible result:
  15. File was last modified (12 hour format):
  16. 01/25/2003 11:38:30 AM
  17. size = 5.8 kb
  18. """
Similarly function os.path.getatime() gives the last access time.
Last edited by vegaseat; Aug 12th, 2009 at 6:00 pm. Reason: tags
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,221
Reputation: bumsfeld will become famous soon enough bumsfeld will become famous soon enough 
Solved Threads: 137
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Nearly a Posting Virtuoso

Re: File Modification Time

 
0
  #3
Jul 2nd, 2006
A kbyte is 1024 bytes. This would be more correct:
  1. fsize = os.path.getsize(fname)
  2. print "size = %0.1f kb" % float(fsize/1024.0)
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC