python文件操作(2)--分析扫描得到的日志文件把文件状态导入Excel表格
2010-04-07 22:07
1141 查看
#通过分析两次的扫描日志,来分析文件的,增,删,改的记录,把分析的结果导入Excel表格。实现文件的日常管理。
import string,os
def GetList(file):#把日志文件转换为list
#第一字典存放文件名后修改时间
dict = {}
fd = open(file,'r')
while 1:
line = fd.readline()
if not line:
break
line = string.strip(line)
#提取文件名,在存入文件的时候用特殊符号修饰
str1 = line[line.find('@'):line.find('*')+1]
#提取文件修改时间
str2 = line[11:19]
if len(line) == 0:
continue
dict[str1] = str2
fd.close()
return dict
if __name__ == '__main__':
flag = ''
f=file('result.xls','w')
f.write('FileName '+'/t'+'Modified time'+'/t'+'state'+'/t'+'/n')
#todayFile = GetList('E://poem.log')
#yesdayFile = GetList('E://poem1.log')
todayLog = raw_input('Input the log of today:')
yesdayLog = raw_input('Input the log of yestoday:')
todayFile = GetList(todayLog)
yesdayFile = GetList(yesdayLog)
for name in todayFile:
if name in yesdayFile:
if todayFile[name]!=yesdayFile[name]:#文件修改过
print name[1:-1],'Modified!'
flag = 'Modified!'
else:#文件保持原样
print name[1:-1],'Ok'
flag = 'Ok!'
continue
else:#新添加的文件
print name[1:-1],'Insert!'
flag = 'Insert!'
f.write(name[1:-1]+'/t'+todayFile[name]+'/t'+flag+'/t'+'/n')
for name in yesdayFile:
if name in todayFile:
continue
else:#删除的文件
print name[1:-1], 'Delete!'
flag = 'Delete!'
f.write(name[1:-1]+'/t'+yesdayFile[name]+'/t'+flag+'/t'+'/n')
print 'Press any key to exit...'
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/liyzh_inspur/archive/2009/02/20/3913991.aspx
import string,os
def GetList(file):#把日志文件转换为list
#第一字典存放文件名后修改时间
dict = {}
fd = open(file,'r')
while 1:
line = fd.readline()
if not line:
break
line = string.strip(line)
#提取文件名,在存入文件的时候用特殊符号修饰
str1 = line[line.find('@'):line.find('*')+1]
#提取文件修改时间
str2 = line[11:19]
if len(line) == 0:
continue
dict[str1] = str2
fd.close()
return dict
if __name__ == '__main__':
flag = ''
f=file('result.xls','w')
f.write('FileName '+'/t'+'Modified time'+'/t'+'state'+'/t'+'/n')
#todayFile = GetList('E://poem.log')
#yesdayFile = GetList('E://poem1.log')
todayLog = raw_input('Input the log of today:')
yesdayLog = raw_input('Input the log of yestoday:')
todayFile = GetList(todayLog)
yesdayFile = GetList(yesdayLog)
for name in todayFile:
if name in yesdayFile:
if todayFile[name]!=yesdayFile[name]:#文件修改过
print name[1:-1],'Modified!'
flag = 'Modified!'
else:#文件保持原样
print name[1:-1],'Ok'
flag = 'Ok!'
continue
else:#新添加的文件
print name[1:-1],'Insert!'
flag = 'Insert!'
f.write(name[1:-1]+'/t'+todayFile[name]+'/t'+flag+'/t'+'/n')
for name in yesdayFile:
if name in todayFile:
continue
else:#删除的文件
print name[1:-1], 'Delete!'
flag = 'Delete!'
f.write(name[1:-1]+'/t'+yesdayFile[name]+'/t'+flag+'/t'+'/n')
print 'Press any key to exit...'
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/liyzh_inspur/archive/2009/02/20/3913991.aspx
相关文章推荐
- python文件操作(2)--分析扫描得到的日志文件把文件状态导入Excel表格
- python文件操作(1)--扫描某目录下的文件列表信息存入日志文件
- Python 脚本学习(三),日志分析脚本,文件差异对比,HTTP状态检测
- oracle expdp导入时 提示“ORA-39002: 操作无效 ORA-39070: 无法打开日志文件 ”
- python导入csv文件出现SyntaxError问题分析
- python分析postfix邮件日志的状态 推荐
- 截取与分析日志文件的特定行数的操作
- Python扫描文件夹&&分析文件
- python---实战日志文件中查找特定字段,文件操作读写、排序、替换、列表、集合
- 第四步 使用shell操作数据库,导入分析并将结果导出成txt文件
- 导入文件的三种方式及分析web服务日志计算元素字节大小案例
- Python生成gexf文件并导入gephi做网络图分析
- hadoop日志分析系统二 第一部分 利用任务调度系统定期的把web系统所产生的日志文件导入到hdfs中
- 截取与分析日志文件的特定行数的操作
- Python 文件操作技巧(File operation) 实例代码分析
- Python 文件操作技巧(File operation) 实例代码分析
- hadoop日志分析系统二 第一部分 利用任务调度系统定期的把web系统所产生的日志文件导入到hdfs中
- python---局域网扫描简化版、平台判断、平台创建文件、文件操作、range、数字列表转成字符列表、不同平台ping操作
- 比较awk python: [文件]web日志信息统计 。 [命令]netstat命令状态统计
- Android SD卡上文件操作及记录日志操作实例分析