I'm trying to write a python script for renaming all of my movie files. What I want to use two text files, one with the names of the filenames of the movies and one with what I want the new name to be, that way I can rename them how I want. I want it to take each line from list_one and rename it to the corresponding line in list_two. Here's what I have so far.
The error I get is 'cannot concatenate 'str' and 'list' objects.' A google search reveal many ways to convert lists into single strings, which would print out all of my movies at once, but I could not find how to do what I need to do.Code:#!/usr/bin/env python import os list_one = open('list_one.txt', 'r'); list_two = open('list_two.txt', 'r'); for line in list_one.readlines(): new_name = list_two.readlines(); if os.system('mv ' , line , ' ' + new_name) == 0: print line + ' has been rename to ' + new_name; else: print 'error' list_one.close() list_two.close()
After that didn't work, I tried this
Here I got the error 'TypeError: coercing to Unicode: need string or buffer, list foundCode:#!/usr/bin/env python import os list_one = open('list_one.txt', 'r'); list_two = open('list_two.txt', 'r'); for line in list_one.readlines(): new_name = list_two.readlines(); if os.rename( line , new_name) == 0: print line + ' has been rename to ' + new_name; else: print 'error' list_one.close() list_two.close()
TypeError:: command not found.' From what I read, os.rename() might not be what I want anyways, because if there is an object with the same name (where there might be in my case) it will be removed silently.
Any suggestions?



Adv Reply





Bookmarks