On 5/18/19 6:52 AM, Alan Gauld via Tutor wrote:
> On 18/05/2019 03:14, Richard Damon wrote:
>> The same directory, running the same program under Mac OS X, which also
>> is a case insensitive file system, 
> That is your mistake. Darwin, the core of the MacOS X system
> is a version of BSD Unix and like all Unix OS is very much
> case sensitive.
> Some of the GUI tools in MacOS X may work as if they were case
> insensitive (presumably for backwards compatibility to MacOS 9)
> but the underlying OS is case sensitive and all the Terminal
> type tools and commands, including Python, follow suit.
Ok, I guess I have gotten used to the GUI tools and their behavior, that
would explain why glob works the way it does.
>> Is there an easy was to make glob match files as a case insensitive manner?
> Depends on what you mean by easy :-)
> You could include both upper and lower case letters in the search:
> glob.glob("[aA][mM][iI][xX][eE][dD][nN][aA][mM][eE]")
> And you could write a helper function to generate the search strings.
> But personally I'd probably just use listdir and compare with
> my search string expressed as a regex.
> for fname in os.listdir('.'):
>     if re.match("aregex", fname)
>        ...
> Another option might be to use fnmatch against the uppercase
> version of the name
> for fname in os.listdir('.'):
>    if fnmatch(pattern, fname.upper())
>      ...

I was hoping for something simpler, but I guess an explicit directory
search isn't that bad.


Richard Damon

Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:

Reply via email to