Reputation: 133
I'm using someone else's code to rename files in a folder sequentially.
import os
_src = ("/Path/To/Directory")
for i,filename in enumerate(os.listdir(_src)):
newname = ('Test-' + str(i).zfill(3))
os.rename(filename, newname)
print('renaming "%s" to "%s"' % (filename,newname))
What is the error in the above snippet?
Upvotes: 0
Views: 1623
Reputation: 403050
You are not specifying the fully qualified path when calling os.rename
. You need:
os.rename(os.path.join(_src, filename), os.path.join(_src, newname))
Upvotes: 3