我需要将所有文件重命名为'DSC0 + num'
,所以文件的最终名称应该是(例如)'DSC02015'
尝试的代码:
import os
path = "C:\\images"
num = 2000
i=0
files = os.listdir(path)
for x in files:
old = files[i]
new = 'DSC0%d' %(num)
os.rename (files[i],new)
num +=1
i +=1
我收到此错误:
Traceback <most recent call last):
File "rename.py", line 10, in <module>
os.rename (files[i],new)
WindowsError: [Error 2] The system cannot find the file specified