美文网首页
批量修改文件名.py

批量修改文件名.py

作者: Aedda | 来源:发表于2020-03-17 10:11 被阅读0次
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)

相关文章

网友评论

      本文标题:批量修改文件名.py

      本文链接:https://www.haomeiwen.com/subject/qcpzehtx.html