python處理下數據小腳本
阿新 • • 發佈:2018-07-11
odi port path remove rem location 所有 子目錄 小腳本 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處理下數據小腳本