一个获取指定目录下一定格式的文件名称和文件修改时间并保存为文件的python脚本
摘自:http://blog.csdn.net/forandever/article/details/5711319
一个获取指定目录下一定格式的文件名称和文件修改时间并保存为文件的python脚本
@for&ever 2010-07-03
功能:
获取指定目录下面符合一定规则的文件名称和文件修改时间,并保存到指定的文件中
脚本如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2010-7-2
@author: forever
'''
import glob, os, datetime
#Windows
filesRead = r"C:/forever/logxyz-*.gif"
fileWrite = r"C:/forever/count.txt"
#Linux
#filesRead = r"/forever/logxyz-*.gif"
#fileWrite = r"/forever/count.txt"
if __name__ == '__main__':
list = glob.glob(filesRead)
# print list
out=open(fileWrite,'w')
out.write('All GIF files:')
out.write('/n')
for i in list:
basename = os.path.basename(i)
#print basename
lastMod = os.path.getmtime(i)
#print lastMod
mydate = datetime.datetime.fromtimestamp(int(lastMod))
#print mydate
out.write('filename:' + basename + ' lastmod:' + str(mydate) )
out.write('/n')
out.close()