import os
import re
filepath = "/media/wang/My Passport/low/low25bird/" # 文件夹路径
delect = ".pcd" # 要删除的名字字符串
if __name__ == "__main__":
if not os.path.exists(filepath):
print("目录不存在!!")
os._exit(1)
filenames = os.listdir(filepath)
print("文件数目为%i" % len(filenames))
count = 0
for name in filenames:
newname = re.sub(delect, '', name)
# newname = 'data'+name # 若想要在名字前面加字符段,可用此语句
os.rename(filepath + '' + name, filepath + '' + newname)
count += 1
if count % 100 == 0:
print("第%i个文件已经改名完成" % count)
Ubuntu pyhon批量删除文件名中的字符串(后缀 前缀)
最新推荐文章于 2022-11-21 13:53:41 发布