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 m

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

Re: simple renaming files program

2010-08-09 Thread Dave Angel
MRAB wrote: from os.path import isdir, join 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. thanks for ke

Re: simple renaming files program

2010-08-09 Thread MRAB
Dave Angel wrote: blur959 wrote: On Aug 9, 6:01 pm, Chris Rebert wrote: 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 name

Re: simple renaming files program

2010-08-09 Thread Dave Angel
blur959 wrote: On Aug 9, 6:01 pm, Chris Rebert wrote: 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 name of the built-in t

Re: simple renaming files program

2010-08-09 Thread blur959
On Aug 9, 6:01 pm, Chris Rebert wrote: > On Mon, Aug 9, 2010 at 2:44 AM, 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 pro

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, filena

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, > the

Re: simple renaming files program

2010-08-09 Thread Shashwat Anand
On Mon, Aug 9, 2010 at 3:14 PM, 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

Re: simple renaming files program

2010-08-09 Thread Chris Rebert
On Mon, Aug 9, 2010 at 2:44 AM, 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