'''
从linux系统中用命令列出,文件名与时间,并用python转成字典
'''
import os
import time
'''
python 获取系统日期
import time
>>> print time.strftime('%Y%m%d',time.localtime())
'''
systime=time.strftime('%Y%m%d',time.localtime())
db={}
fileTimeName=os.popen("ls -l --time-style=+%Y%m%d test/| grep -v total | awk '{print $6,$7}'").readlines()
for i in fileTimeName:
d=i[:8]
#print d
v=i[9:].strip('\n')
#print v
if d not in db:
db[d]=[v] #将V定义成列表,d不在db字典中直接添加v值
else:
db[d].append(v) #如果db字典中存在d,则将v以列表形式追加
print 'hello'
print db
>>> print db
for i in db.iterkeys():
timeCha=int(systime)-int(i)
if timeCha == 1:
print i,timeCha
else:
print i,'timeCha large than 1'
阅读(1216) | 评论(0) | 转发(0) |