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


Groups > comp.lang.python > #64601 > unrolled thread

Re: Case insensitive exists()?

Started byTim Chase <python.list@tim.thechases.com>
First post2014-01-23 06:48 -0600
Last post2014-01-23 06:48 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#64601 — Re: Case insensitive exists()?

FromTim Chase <python.list@tim.thechases.com>
Date2014-01-23 06:48 -0600
SubjectRe: Case insensitive exists()?
Message-ID<mailman.5885.1390481274.18130.python-list@python.org>
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


[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web