Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #64547

Re: Case insensitive exists()?

References <mailman.5853.1390438708.18130.python-list@python.org> <roy-7A7FAE.20082622012014@news.panix.com>
Date 2014-01-22 18:18 -0700
Subject Re: Case insensitive exists()?
From Larry Martell <larry.martell@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.5855.1390439920.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Jan 22, 2014 at 6:08 PM, Roy Smith <roy@panix.com> wrote:
> In article <mailman.5853.1390438708.18130.python-list@python.org>,
>  Larry Martell <larry.martell@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.

Yes, match the file names. e.g. if my match string is "ABC" and
there's a file named "Abc" then it would be match.

> 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".

The issue is that I run a database query and get back rows, each with
a file path (each in a different dir). And I have to check to see if
that file exists. Each is a separate search with no correlation to the
others. I have the full path, so I guess I'll have to do dir name on
it, then a listdir then compare each item with .lower with my string
.lower. It's just that the dirs have 100's and 100's of files so I'm
really worried about efficiency.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Case insensitive exists()? Larry Martell <larry.martell@gmail.com> - 2014-01-22 17:58 -0700
  Re: Case insensitive exists()? Roy Smith <roy@panix.com> - 2014-01-22 20:08 -0500
    Re: Case insensitive exists()? Larry Martell <larry.martell@gmail.com> - 2014-01-22 18:18 -0700
      Re: Case insensitive exists()? Roy Smith <roy@panix.com> - 2014-01-22 20:27 -0500
        Re: Case insensitive exists()? Larry Martell <larry.martell@gmail.com> - 2014-01-22 21:24 -0700
        Re: Case insensitive exists()? Chris Angelico <rosuav@gmail.com> - 2014-01-23 15:29 +1100
        Re: Case insensitive exists()? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2014-01-23 15:43 +0000
        Re: Case insensitive exists()? Larry Martell <larry.martell@gmail.com> - 2014-01-23 12:02 -0700
      Re: Case insensitive exists()? Dan Sommers <dan@tombstonezero.net> - 2014-01-23 07:51 +0000
  Re: Case insensitive exists()? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-23 12:06 +0000
  Re: Case insensitive exists()? Grant Edwards <invalid@invalid.invalid> - 2014-01-23 14:58 +0000

csiph-web