From: blur959 on 12 Aug 2010 09:15 Hi all, I am creating a program that renames all files of the similar file type. But i am stuck at this part. I tried running this code and I got this error: new_name = os.rename(path, newpath) WindowsError: [Error 183] Cannot create a file when that file already exists. Hope you guys could help. import os directory = raw_input("Please input file directory. \n\n") s = raw_input("Please input a name to replace. \n\n") ext = raw_input("input file ext") for filename in listdir(directory): if ext in filename: path = join(directory, filename) fnpart = os.path.splitext(filename)[0] replace_name = filename.replace(fnpart, s) newpath = os.path.join(directory, replace_name) new_name = os.rename(path, newpath) print new_name
From: MRAB on 12 Aug 2010 12:16 blur959 wrote: > Hi all, I am creating a program that renames all files of the similar > file type. But i am stuck at this part. I tried running this code and > I got this error: new_name = os.rename(path, newpath) > WindowsError: [Error 183] Cannot create a file when that file already > exists. Hope you guys could help. > [snip] As the traceback says, a file with that new name already exists. You can't have 2 files with the same name in the same folder.
|
Pages: 1 Prev: Secure LDAP Configuration Next: Programming Puzzles? What's your favorite puzzle? |