根据某位师兄的笔记整理:
import os
import xlwt
dir = []
name = []
version = []
def file_name(file_dir):
for root, dirs, files in os.walk(file_dir):
root_split = root.split("\\")
if root_split[-1].startswith('v'):
dir.append(root)
name.append(root_split[-2])
version.append(root_split[-1])
if __name__ == '__main__':
file_name(r'\\192.168.199.199\测试')
ws = xlwt.Workbook(encoding='utf-8')
w = ws.add_sheet('Sheet1')
w.write(0, 0, r'模块名称')
w.write(0, 1, r'模块版本号')
w.write(0, 2, r'程序路径')
w.write(0, 3, r'备注')
for i in range(len(dir)):
w.write(i + 1, 0, name[i])
w.write(i + 1, 1, version[i])
w.write(i + 1, 2, dir[i])
ws.save('example.xls')