File Modification Time | DaniWeb

File Modification Time | DaniWeb,第1张

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. """

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/2086030.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-07-22
下一篇 2022-07-22

发表评论

登录后才能评论

评论列表(0条)

保存