原来是这样的

python实现文件名称批量修改(删除名称中特定字符)

 

 

 

import os

# 输入文件夹地址
path = r"C:\Users\Downloads\Video"
files = os.listdir(path)

# 输出所有文件名,只是为了看一下
for file in files:
    print(file)

# 获取旧名和新名
i = 0
for file in files:
    # old 旧名称的信息
    old = path + os.sep + files[i]
    # new是新名称的信息,这里的操作是删除了最前面的'考拉很忙o - '共8个字符
    new = path + os.sep + file.replace('考拉很忙o - ','')
    # 新旧替换
    os.rename(old,new)
    i+=1

 

相关文章:

  • 2023-03-15
  • 2021-12-13
  • 2021-12-13
  • 2021-05-31
  • 2021-11-21
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
  • 2021-11-18
  • 2021-08-23
  • 2021-07-18
相关资源
相似解决方案