批量修改文件名.py

2020-03-17  本文已影响0人  Aedda
import os
import re

def rename_batch(path):
    for file in os.listdir(path):
        fileNew= '_youkushipin_'
        fileNew=re.sub(r'_.*?_', fileNew, file, 1, flags=re.I)
        if '.pcap' == file[-5:]:
            print(fileNew)
            os.rename(path+ '\\' + file, path + '\\' + fileNew)

path=r'C:\Users\Administrator\Desktop\svn备份\pcap\优酷视频'
rename_batch(path)
上一篇 下一篇

猜你喜欢

热点阅读