File Modification Time | DaniWeb

File Modification Time | DaniWeb

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. # pick a file you have in the working folder ...
  4. fname = "Texture.py"
  5. print "File was last modified (12 hour format):"
  6. print time.strftime("%m/%d/%Y %I:%M:%S %p",time.localtime(os.path.getmtime(fname)))
  7. fsize = os.path.getsize(fname)
  8. print "size = %0.1f kb" % float(fsize/1000.0)
  9. """
  10. possible result:
  11. File was last modified (12 hour format):
  12. 01/25/2003 11:38:30 AM
  13. size = 5.8 kb
  14. """

你可能感兴趣的:(File)