Re: simple renaming files program

2010-08-09 Thread Chris Rebert
On Mon, Aug 9, 2010 at 2:44 AM, blur959 blur...@hotmail.com wrote: Hi, all, I am working on a simple program that renames files based on the directory the user gives, the names the user searched and the names the user want to replace. However, I encounter some problems. When I try running the

Re: simple renaming files program

2010-08-09 Thread Shashwat Anand
On Mon, Aug 9, 2010 at 3:14 PM, blur959 blur...@hotmail.com wrote: Hi, all, I am working on a simple program that renames files based on the directory the user gives, the names the user searched and the names the user want to replace. However, I encounter some problems. When I try running the

Re: simple renaming files program

2010-08-09 Thread Ulrich Eckhardt
blur959 wrote: Hi, all, I am working on a simple program that renames files based on the directory the user gives, the names the user searched and the names the user want to replace. However, I encounter some problems. When I try running the script, when it gets to the os.rename part, there

Re: simple renaming files program

2010-08-09 Thread Peter Otten
Chris Rebert wrote: Hence (untested): from os import listdir, rename from os.path import isdir, join directory = raw_input(input file directory) s = raw_input(search for name) r = raw_input(replace name) for filename in listdir(directory): path = join(directory, filename) #paste the

Re: simple renaming files program

2010-08-09 Thread blur959
On Aug 9, 6:01 pm, Chris Rebert c...@rebertia.com wrote: On Mon, Aug 9, 2010 at 2:44 AM, blur959 blur...@hotmail.com wrote: Hi, all, I am working on a simple program that renames files based on the directory the user gives, the names the user searched and the names the user want to replace.

Re: simple renaming files program

2010-08-09 Thread Dave Angel
blur959 wrote: On Aug 9, 6:01 pm, Chris Rebert c...@rebertia.com wrote: snip os.rename() takes paths that are absolute (or possibly relative to the cwd), not paths that are relative to some arbitrary directory (as returned by os.listdir()). Also, never name a variable file; it shadows the

Re: simple renaming files program

2010-08-09 Thread MRAB
Dave Angel wrote: blur959 wrote: On Aug 9, 6:01 pm, Chris Rebert c...@rebertia.com wrote: snip os.rename() takes paths that are absolute (or possibly relative to the cwd), not paths that are relative to some arbitrary directory (as returned by os.listdir()). Also, never name a variable file;

Re: simple renaming files program

2010-08-09 Thread Dave Angel
MRAB wrote: snip from os.path import isdir, join snip Have a look at the imports, Dave. :-) Oops. I should have noticed that it was a function call, not a method. And there's no built-in called join(). I just usually avoid using this kind of alias, unless performance requires.

Re: simple renaming files program

2010-08-09 Thread Chris Rebert
On Mon, Aug 9, 2010 at 3:19 AM, Peter Otten __pete...@web.de wrote: Chris Rebert wrote: Hence (untested): from os import listdir, rename from os.path import isdir, join directory = raw_input(input file directory) s = raw_input(search for name) r = raw_input(replace name) for filename in

Re: simple renaming files program

2010-08-09 Thread Peter Otten
Chris Rebert wrote: On Mon, Aug 9, 2010 at 3:19 AM, Peter Otten __pete...@web.de wrote: Warning: I don't remember how Windows handles this, but unix will happily perform os.rename(alpha/alpha.txt, beta/beta.txt) and overwrite beta/beta.txt with alpha/alpha.txt. I'd rather modify the