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