python遍历是什么意思_python遍历

#coding=utf-8

'''Created on 2018年8月28日

@author:yanerfree

get the version number of the file (.dll) in bulk

批量获取dll文件的版本号'''

importosimportsysimportwin32apiimportxlwtfrom xlwt import *

classGetFileVersionNo():def __init__(self,file_path,save_path):#初始化

self.file_path =file_path

self.save_path=save_pathdeftraverse_dir(self,file_path):#traverse the directory of file_path(the file are .dll)

myList=[]#save result

list =os.listdir(file_path)for i inrange(0,len(list)):printlist[i]

tmp_path=os.path.join(file_path,list[i])printtmp_pathifos.path.isfile(tmp_path):#if str(list[i]).split(".")[1] =="dll":

if str(list[i])[-3:] == "dll":#judge if the filename ended with ".dll"

#print tmp_path,getFileVersion(tmp_path)

myList.append((list[i],self.getFileVersion(tmp_path)))returnmyListdefgetFileVersion(self,file_name):#get the version of file

info =win32api.GetFileVersionInfo(file_name, os.sep)

ms= info['FileVersionMS']

ls= info['FileVersionLS']

version= '%d.%d.%d.%04d' %(win32api.HIWORD(ms), win32api.LOWORD(ms), win32api.HIWORD(ls), win32api.LOWORD(ls))printversionreturnversiondefwriteToExcel(self):

file_path=self.file_path

save_path=self.save_path#write to excel

print "create a workbook"book= Workbook(encoding='utf-8')#create a workbook

sheet = book.add_sheet('Sheet1')#create a sheet

#set style

font = xlwt.Font() #字体

font.name = 'Times New Roman'font.bold=True

font.underline=False

font.italic=False

style= xlwt.XFStyle() #创建一个格式

style.font = font #设置格式字体

#sheet.write(0, 0, label = 'Formatted value', style) # Apply the Style to the Cell

sheet.write(0, 0, "no",style)

sheet.write(0,1, "file_name",style)

sheet.write(0,2, "file_version",style)

list=self.traverse_dir(file_path)

row=0

num=0for item inlist:

row+= 1num+= 1sheet.write(row, 0, num, style)

sheet.write(row,1,item[0] , style)

sheet.write(row,2,item[1] , style)

book.save(save_path)if __name__ == '__main__':#1)获取指定目录下dll文件的版本号

file_path1 = r'../01_dev/Exts'save_path1= r'../04_result/result_dev.xls'getVersion1=GetFileVersionNo(file_path1,save_path1)

getVersion1.writeToExcel()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值