python os.listdir按文件存取时间顺序列出目录的实例

yipeiwu_com6年前Python基础

如下所示:

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按文件存取时间顺序列出目录的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python正则表达式re模块详解

快速入门 import re pattern = 'this' text = 'Does this text match the pattern?' match = re...

对Python3.x版本print函数左右对齐详解

数字的情况: a = 5 , b = 5.2,c = "123456789" 最普通的右对齐:print("%3d"%a) 输出 5(详情:5前面两个空格) print("%10.3f"...

使用pandas把某一列的字符值转换为数字的实例

今天小编就为大家分享一篇使用pandas把某一列的字符值转换为数字的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧 使用map的方法就可以实现把某一列的字符类型的值...

Puppeteer使用示例详解

Puppeteer使用示例详解

PhantomJS曾经是无头浏览器里的王者,测试、爬虫等都在使用,随着GoogleChrome Headless的出现,PhantomJS的作者已经明确表示不在更新,而GoogleChr...

python实现抖音点赞功能

本文实例为大家分享了python实现抖音点赞功能的具体代码,供大家参考,具体内容如下 #coding=utf-8 from time import sleep, ctime imp...