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


Groups > comp.lang.python > #64601

Re: Case insensitive exists()?

Date 2014-01-23 06:48 -0600
From Tim Chase <python.list@tim.thechases.com>
Subject Re: Case insensitive exists()?
References <CACwCsY45rqTQO+AGw6029g_i91zeP9uwWaGTQ4WtbaZgTtptEQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.5885.1390481274.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 2014-01-22 17:58, Larry Martell 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. Does
> anyone know of an efficient way to do this? There's no switch for
> os.path that makes exists() check case-insensitively is there?

Is it possible to rephrase the problem in terms of a different
algorithm that can be made case-insensitive?  Something like

  from_db = set(
    row[0].upper()
    for row in db.execute(
      "select filename from tblfoo where ..."
      ).fetchall()
    )
  from_fs = dict(
    (fname.upper(), os.path.join(pth, fname))
    for pth, dirs, files in os.walk(ROOT)
    for fname in files
    )
  common_filenames = from_db & set(from_fs)
  for fname in common_filenames:
    print from_fs[fname]

-tkc


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


Thread

Re: Case insensitive exists()? Tim Chase <python.list@tim.thechases.com> - 2014-01-23 06:48 -0600

csiph-web