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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -