标签:python sdi ace new listdir 遍历 utf-8 move code
python处理下数据小脚本# -*- coding:UTF-8 -*-
import os
def wenjchuli(file_path):
with open(file_path) as f, open(file_path+".bak", ‘w‘) as f2:
for line in f:
if("Location" in line):
new_line=line.replace(line,"")
elif("Qualified Name" in line):
new_line=line.replace(line,"")
elif ("JD-Core Version" in line):
new_line = line.replace(line, "")
elif ("/*" in line):
new_line = line[12:].replace("/", "")
else:
new_line = line
f2.write(new_line)
os.remove(file_path)
os.rename(file_path+".bak",file_path)
def gci(filepath):
# 遍历filepath下所有文件,包括子目录
files = os.listdir(filepath)
for fi in files:
fi_d = os.path.join(filepath, fi)
if os.path.isdir(fi_d):
gci(fi_d)
else:
wenjchuli(fi_d)
gci("C:\\Users\\lw\\Desktop\\letv")
标签:python sdi ace new listdir 遍历 utf-8 move code
原文地址:http://blog.51cto.com/357712148/2140144