Friday, 15 February 2013

filenames - Python os.rename and os.walk together -


I have just written a python script to get rid of some annoying suffixes in file names,

Here is my code: Import the OS for the OS for the root, files in the OS Walk ("Path"): for file name in the file: if filename.endswith ("[annoyingtag ] .mov "): OS

But I got an error in the previous row:

  OSError: [name] Rename the file [File name, File name [: - 18] + '. Mov 'Errno 2] Any such file or directory   

I'm pretty sure I have the right path because I can print all the filenames correctly.

... in fact it is not known why it can not work.

Thank you for your reply

You

  os.rename (file name, file name [: - 18] + '.mov')   

  os .rename (root + os.sep + filename, root + os.sep + filename [: - 18] + '.mov')    

No comments:

Post a Comment