python - No such file or directory error? -
i'm using else's code rename files in folder sequentially.
import os _src = ("/path/to/directory") i,filename in enumerate(os.listdir(_src)): newname = ('test-' + str(i).zfill(3)) os.rename(filename, newname) print('renaming "%s" "%s"' % (filename,newname))
what error in above snippet?
you not specifying qualified path when calling os.rename
. need:
os.rename(os.path.join(_src, filename), os.path.join(_src, newname))
Comments
Post a Comment