我需要的所有文件重命名爲'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