首页 > 代码库 > python 根据文件创建时间排序

python 根据文件创建时间排序

#coding:utf8import os,timedirectory = "d:/scrapy tutorial/"t = []d = {}for filename in os.listdir(directory):        path = directory + filename        time1 = time.ctime(os.path.getmtime(path))        d[time1] = filename        t.append(time1)n = 1for i in sorted(t):        fn = directory + d[i]        new_fn = directory + str(n) + ‘. ‘ + d[i]##        if n<10:##                new_fn = directory + d[i][1:]##        else:##                new_fn = directory + d[i][2:]        os.rename(fn, new_fn)        n += 1

  临时写的一个脚本,可以用在那些不支持按时间排序、默认按[0-9a-Z]排序的系统上

python 根据文件创建时间排序