美文网首页
批量替换当前文件夹下的名称-python

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

作者: Leo_23 | 来源:发表于2020-06-06 14:28 被阅读0次

因为下载下来的带广告的文件,批量替换个别字符为空。
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

相关文章

网友评论

      本文标题:批量替换当前文件夹下的名称-python

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