python批处理代码_【原创源码】【python】python文本文件批处理
[Python] 純文本查看 復制代碼import os
import shutil
def text_edit_vhd(filepath):
with open(filepath,'r+') as file_head:
content = file_head.read()
file_head.seek(0,0)
file_head.write("`protect begin \n" + content)
file_head.seek(0,2)
file_head.write("\n`protect end ")
def text_edit_v(filepath):
with open(filepath,'r+') as file_head:
content = file_head.read()
file_head.seek(0,0)
file_head.write("`protect \n"+ content)
file_head.seek(0,2)
file_head.write(" \n`endprotect ")
def add_text(srcpath): #尋找本文件夾及子文件夾下所以符合要求的文本進行處理
srcdirs = os.listdir(srcpath)
for dir in srcdirs:
if not os.path.isfile(os.path.join(srcpath, dir)): #判斷dir屬性,為文件或者文件夾
add_text(os.path.join(srcpath, dir))
else :
if '.vhd' == dir[-4: ]:
print("正在處理文件中,文件路徑為:"+os.path.join(srcpath, dir))
text_edit_vhd(os.path.join(srcpath, dir))
print("文件處理完成!")
elif '.v' == dir[-2:] :
print("正在處理文件中,文件路徑為:"+os.path.join(srcpath, dir))
text_edit_v(os.path.join(srcpath, dir))
print("文件處理完成!")
path = os.getcwd()
print('當前文件路徑為:'+ path)
os.chdir('..')
root_path = os.getcwd()
handle_path = root_path + '\handle'
print('當前文件路徑為:' + handle_path)
shutil.copytree(path,handle_path) #備份后進行數(shù)據(jù)處理
add_text(handle_path)
print("run done\n")
總結(jié)
以上是生活随笔為你收集整理的python批处理代码_【原创源码】【python】python文本文件批处理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mybatis 映射成多个list_SS
- 下一篇: websocket python爬虫_p