找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 13525|回复: 1

[原创代码] python读取文件创建时间修改时间.py

[复制链接]
发表于 2016-2-26 04:24:49 | 显示全部楼层 |阅读模式
python读取文件创建时间修改时间.py
  1. """
  2. python读取文件创建时间修改时间.py
  3. http://www.oschina.net/code/snippet_191887_54050
  4. 2016年2月26日 02:55:20 codegay
  5. windows python读取文件的修改时间,创建时间,访问时间信息
  6. 需要自己使用time模块进行转换处理
  7. """
  8. import os
  9. import time

  10. for r in os.listdir("."):
  11.     if r.endswith(".py"):
  12.         t=os.stat(r)
  13.         print(t)
  14.         print("修改时间:",t.st_mtime)
  15.         print(time.localtime(t.st_mtime))
  16.         print("创建时间?",time.localtime(t.st_ctime))
  17.         print("访问时间:",time.ctime(t.st_atime))

  18. #读取目录的时间        
  19. t=os.stat("c:/windows")
  20. print(t)
  21. print("修改时间:",t.st_mtime)
  22. print(time.localtime(t.st_mtime))
  23. print("创建时间?",time.localtime(t.st_ctime))
  24. print("访问时间:",time.ctime(t.st_atime))
复制代码

评分

参与人数 1技术 +1 收起 理由
CrLf + 1 感谢分享

查看全部评分

 楼主| 发表于 2016-3-2 13:26:39 | 显示全部楼层
  1. """
  2. python取出当前目录下最新修改的文件.py
  3. http://bbs.bathome.net/thread-39535-1-1.html
  4. 2016年3月2日 11:44:35 codegay
  5. 参考资料 python glob模块 通配符
  6. http://blog.sina.com.cn/s/blog_5ee725480101bf94.html
  7. """
  8. import os
  9. import glob
  10. import shutil
  11. #os.mkdir("电路图")
  12. fs=glob.glob("*总成电路图.pdf")
  13. 电路图={r:os.stat(r).st_mtime for r in fs}
  14. ns=max(电路图)
  15. print("最新",max(电路图))
  16. shutil.copy(ns,"./电路图/")

  17. fs=glob.glob("*总成明细表.pdf")
  18. 明细表={r:os.stat(r).st_mtime for r in fs}
  19. print("最新",max(明细表))
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 06:30 , Processed in 0.016909 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表