Make all files extension lower by a given directory name
Tiefeng Wu
icebergwtf at yahoo.com.cn
Fri Nov 3 01:03:40 EST 2006
Tim Chase wrote:
> Having a win32 program take case-sensitive filenames is a bit
> odd, given that the OS is case-agnostic...however, that doesn't
> preclude bad programming on the part of your tool-maker. Alas.
>
> Thus, to accomodate the lousy programming of your tool's maker, I
> proffer this:
>
> I've found that Win32 doesn't often take a rename if the origin
> and destination differ only in case[*]. Thus, to change the
> case, I've had to do *two* renames...one to, say, prefix with an
> underscore and change the case to my desired case, and then one
> to strip off the leading underscore. You might try a similar
> song-and-dance to strong-arm Windows into specifying the case of
> the file. Something like this (untested) code:
>
> filename = "Spanish Inquisition.TGA"
> name, ext = splitext(filename)
> intermediate = "_" + name + ext.lower()
> rename(filename, intermediate)
> rename(intermediate, intermediate[1:])
>
> And then I'd wrap this contrived abomination in plenty of
> comments so that folks coming back to it understand why you're
> using three lines to do what "should" be just
>
> rename(filename, name + ext.lower())
>
> as would be the "right" way to rename the file with a lowercase
> version of its extension.
>
> Yes, it's an odd filename choice there which you might not have
> expected...nobody expects the Spanish Inquisition...
>
> -tkc
>
> [*] Have had problems with this both in Explorer and at the
> command prompt.
Yes, that's tool maker's fault. I think he used string compare in his code with
case-sensitive (coded in c#, btw).
I started study python about a month, so I hope my problem not bother you :)
Anyway, I realize python is an amazing language and a power tool, thank you.
wutiefeng
2006-11-03
___________________________________________________________
雅虎免费邮箱-3.5G容量,20M附件
http://cn.mail.yahoo.com/
More information about the Python-list
mailing list