Lol, that was a result of my search and replace... not a name I made up. I meant that to say directory rather than topectory.

Quentin Hartman wrote:


On 3/27/06, *Martin Kelly* <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:

    Hi, I was creating a python script to rename all files in a directory as
    specified by a given pattern. I know there are already programs that can
    do this, but I am doing this as a learning exercise.

    The format for the command is like this:
    rename /home foo bar
    ... to change everything in /home with "foo" in it to "bar"

    I got it working, but it's rather messy, and I was wondering if there's
    a more elegant way to do it; after all, it is python :).

    The .py file is attached.


On first glance it looks pretty OK. I am not a python guru, but algorithmically I don't see anything immediately that could be optimized. Syntactically you can likely "compress" it, but I don't really see the value in that. You might consider using the regex module to make it more flexible. As it sits, it seems it would not match on mixed case, partial renames (moving 123foo.txt to 123bar.txt for instance), and would likely break on files with spaces in them.

A bit of an aside here, but what is a "topectory"? I gathered from context that it is the top-level directory that you are working on... but, yeah. Not even google has ever seen "topectory" before. Personally, I have to spend a lot of time at work training people the correct terms for things. There have been a lot of local colloquialisms developed here around technology and it is a real hindrance to communication when people work with others who do not know them. If they had been taught the recognized terms for things right from the get go, they would have been better off in the long term, even if it was marginally more difficult to teach them those terms initially. Using "real" terminology whenever you can is definitely a good practice and will limit headaches down the road.

--
-Regards-

-Quentin Hartman-


------------------------------------------------------------------------

_______________________________________________
EUGLUG mailing list
euglug@euglug.org
http://www.euglug.org/mailman/listinfo/euglug

--
-Martin
_______________________________________________
EUGLUG mailing list
euglug@euglug.org
http://www.euglug.org/mailman/listinfo/euglug

Reply via email to