Case insensitive exists()?
Roy Smith
roy at panix.com
Wed Jan 22 20:08:26 EST 2014
In article <mailman.5853.1390438708.18130.python-list at python.org>,
Larry Martell <larry.martell at gmail.com> wrote:
> I have the need to check for a files existence against a string, but I
> need to do case-insensitively. I cannot efficiently get the name of
> every file in the dir and compare each with my string using lower(),
> as I have 100's of strings to check for, each in a different dir, and
> each dir can have 100's of files in it.
I'm not quite sure what you're asking. Do you need to match the
filename, or find the string in the contents of the file? I'm going to
assume you're asking the former.
One way or another, you need to iterate over all the directories and get
all the filenames in each. The time to do that is going to totally
swamp any processing you do in terms of converting to lower case and
comparing to some set of strings.
I would put all my strings into a set, then use os.walk() traverse the
directories and for each path os.walk() returns, do "path.lower() in
strings".
More information about the Python-list
mailing list