Case insensitive exists()?

Larry Martell larry.martell at gmail.com
Wed Jan 22 23:24:54 EST 2014


On Wed, Jan 22, 2014 at 6:27 PM, Roy Smith <roy at panix.com> wrote:
> In article <mailman.5855.1390439920.18130.python-list at python.org>,
>  Larry Martell <larry.martell at gmail.com> wrote:
>
>> 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.
>
> Oh, my, this is a much more complicated problem than you originally
> described.

I try not to bother folks with simple problems ;-)

> Is the whole path case-insensitive, or just the last component?  In
> other words, if the search string is "/foo/bar/my_file_name", do all of
> these paths match?
>
> /FOO/BAR/MY_FILE_NAME
> /foo/bar/my_file_name
> /FoO/bAr/My_FiLe_NaMe

Just the file name (the basename).

> Can you give some more background as to *why* you're doing this?
> Usually, if a system considers filenames to be case-insensitive, that's
> something that's handled by the operating system itself.

I can't say why it's happening. This is a big complicated system with
lots of parts. There's some program that ftp's image files from an
electron microscope and stores them on the file system with crazy
names like:

2O_TOPO_1_2O_2UM_FOV_M1_FX-2_FY4_DX0_DY0_DZ0_SDX10_SDY14_SDZ0_RR1_TR1_Ver1.jpg

And something (perhaps the same program, perhaps a different one)
records this is a database. In some cases the name recorded in the db
has different cases in some characters then how it was stored in the
db, e.g.:

2O_TOPO_1_2O_2UM_Fov_M1_FX-2_FY4_DX0_DY0_DZ0_SDX10_SDY14_SDZ0_RR1_TR1_Ver1.jpg

These only differ in "FOV" vs. "Fov" but that is just one example.

I am writing something that is part of a django app, that based on
some web entry from the user, I run a query, get back a list of files
and have to go receive them and serve them up back to the browser. My
script is all done and seem to be working, then today I was informed
it was not serving up all the images. Debugging revealed that it was
this case issue - I was matching with exists(). As I've said, coding a
solution is easy, but I fear it will be too slow. Speed is important
in web apps - users have high expectations. Guess I'll just have to
try it and see.



More information about the Python-list mailing list