import os
path = r"C:\your_dir"#i've added r for skipping slash , case you are in windows
os.chdir(path)#well here were the problem , before edit you were in different directory and you want edit file which is in another directory , so you have to change your directory to the same path you wanted to change some of it's file
files = os.listdir(path)
for file in files:
name,ext = file.split('.')
edited_name=str(int(name)-1)
os.rename(file,edited_name+'.'+ext)
您可以使用一个简单的循环:
就这样:)
循环确实是最简单的。作为
str(i).zfill(3) + ".png"
的替代方法,可以使用希望这就是你所期待的
相关问题 更多 >
编程相关推荐