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. """
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。