names = os.listdir("d:/code_me/pos_module_learn/批量修改文件名") #这里根据自己要测试的路径去写 for name in names: basis_path = "d:/code_me/pos_module_learn/批量修改文件名/" src = basis_path+name #原始路径 name0 = os.path.splitext(name) name1 = name0[0] + "20221204" +name0[1] dst = basis_path + name1 os.renames(src,dst)
之前没有设置原路径跟最终路径会报错,现在加上去了就不会报错了
names = os.listdir("d:/code_me/pos_module_learn/批量修改文件名")
for name in names:
basis_path = "d:/code_me/pos_module_learn/批量修改文件名/"
src = basis_path+name #原始路径
name0 = os.path.splitext(name)
name1 = name0[0] + "20221204" +name0[1]
dst = basis_path + name1
os.renames(src,dst)