Renaming files in Python: No such file or directory -


if try rename files in directory, reason error. think problem may have not inserted directory in proper format ?

additional info: python 2 & linux machine

oserror: [errno 2] no such file or directory

though prints directories content fine. doing wrong?

import os  in os.listdir("/home/fanna/videos/strange"):     #print str(i)     os.rename(i, i[:-17]) 

os.rename() expecting full path file want rename. os.listdir returns filenames in directory. try this

import os basedir = "/home/fanna/videos/strange/" in os.listdir( basedir ):     os.rename( basedir + i, basedir + i[:-17] ) 

Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -