如下所示:
import os DIR = "/home/serho/workspace/lisp" def compare(x, y): stat_x = os.stat(DIR + "/" + x) stat_y = os.stat(DIR + "/" + y) if stat_x.st_ctime < stat_y.st_ctime: return -1 elif stat_x.st_ctime > stat_y.st_ctime: return 1 else: return 0 iterms = os.listdir(DIR) iterms.sort(compare) for iterm in iterms: print iterm
以上这篇python os.listdir按文件存取时间顺序列出目录的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
继续阅读与本文标签相同的文章
上一篇 :
Twitter警告所有用户更改密码
下一篇 :
2018年Github上值得学习的十个热门项目
-
开发者必读 · 周报 | 003期
2026-05-18栏目: 教程
-
科技巨头正在合作解决自动驾驶标准!
2026-05-18栏目: 教程
-
人工智能帮助设计自行车并打破竞速纪录
2026-05-18栏目: 教程
-
分层存储超详细解读,为什么大数据时代它已不可或缺
2026-05-18栏目: 教程
-
3D打印在玩具行业的应用
2026-05-18栏目: 教程
