批量替换当前文件夹下的名称-python

2020-06-06  本文已影响0人  Leo_23

因为下载下来的带广告的文件,批量替换个别字符为空。
Rename file names by python

#!/usr/bin/env python
# -*- coding: utf-8 -*-

__author__ = "leo"
__time__ = "2018-05-17"

'''
批量修改文件名称
'''

import os

path = os.path.dirname(__file__)

for file in os.listdir(path):
    if os.path.isfile(os.path.join(path, file)) == True:
        try:
            new_name = file.replace("需要替换的文字", "")
            os.rename(os.path.join(path, file), os.path.join(path, new_name))
        except Exception as e:
            pass
上一篇 下一篇

猜你喜欢

热点阅读