Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-05

Case insensitive FindFirst and friends

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Brad Campbell

G'day all,

I've got a little application I'm working on that is compiled for Darwin, Linux and Win32 and I've bumped up against case sensitivity in FindFirst and friends.

In this application I'm populating a stringlist with a list of files in a directory with a specific extension, but of course I've just realised that the case of that extension is tripping me up. Is there a better way to achieve what I want in a cross platform manner while retaining the case insensitivity?

findfirst('/home/brad/*.abc',$7F,sRec) Won't list any files with a capital in the extension anywhere (as I guess you'd expect with a case sensitive filesystem). Unfortunately this application is being used to help users migrate away from the popular OS with the case insensitive filesystem and they are finding it difficult to cope with this behaviour.

I could write my own case insensitive search I guess (I had to do that elsewhere for another reason) but I thought I'd ask if there was a more standard way to solve the problem?

Regards,
Brad

Dolphins are so intelligent that within a few weeks they can train Americans to stand at the edge of the pool and throw them fish.

Reply by email

Jonas Maebe
to Brad Campbell
Brad Campbell wrote 5 lines
In this application I'm populating a stringlist with a list of files in a directory with a specific extension, but of course I've just realised that the case of that extension is tripping me up. Is there a better way to achieve what I want in a cross platform manner while retaining the case insensitivity?

The only way is reading the entire directory in memory, and then performing your own case-insensitive search on that. The compiler does the same (see compiler/cfileutl.pas -- or do not look at it, depending on the license of your program, since that code is GPL). The big downside of this approach is that it can introduce very noticeable delays in your program's operation when working on networked file systems (especially if there are lots of files in a directory).

I think the only real solution is accept that different OSes do not behave exactly the same, as this will by no means be the only difference they'll encounter. You will not be able to "fix" all of them, unless you start really emulating one OS on top of the others (in which case you'll alienate the "native" users of that platform). And almost every single one of those changes will make your program slower, harder to maintain and harder to port.

Jonas

Reply by email

Brad Campbell
to Jonas Maebe
Jonas Maebe wrote 16 lines
On 18 May 2009, at 08:18, Brad Campbell wrote: > In this application I'm populating a stringlist with a list of files > in a directory with a specific extension, but of course I've just > realised that the case of that extension is tripping me up. Is there a > better way to achieve what I want in a cross platform manner while > retaining the case insensitivity? The only way is reading the entire directory in memory, and then performing your own case-insensitive search on that. The compiler does the same (see compiler/cfileutl.pas -- or do not look at it, depending on the license of your program, since that code is GPL). The big downside of this approach is that it can introduce very noticeable delays in your program's operation when working on networked file systems (especially if there are lots of files in a directory).

Yes, I've done it this way previously (and even in another component of this software). I just wondered if there was a better way. OSX can be a little slow over the network sometimes, but it's not proved a big issue.

Show quoted text 7 lines
I think the only real solution is accept that different OSes do not behave exactly the same, as this will by no means be the only difference they'll encounter. You will not be able to "fix" all of them, unless you start really emulating one OS on top of the others (in which case you'll alienate the "native" users of that platform). And almost every single one of those changes will make your program slower, harder to maintain and harder to port.

Unfortunately this software is being used by people who tend to transport their data from platform to platform, and they expect the software to be bug for bug compatible across all the platforms. I'll just have a play with making the case insensitive search as efficient as I can and leave it at that. I have different key maps across the platforms, serial handling is also different, but things like file names are a sticky one. People expect to share one directory on a server and access it from the three platforms and get the same results.

Thanks for the advice :)

Regards,

Dolphins are so intelligent that within a few weeks they can train Americans to stand at the edge of the pool and throw them fish.

Reply by email

dmitry boyarintsev
to Jonas Maebe: The only way is reading the entire directory in memory, and then performing your own…
I think the only real solution is accept that different OSes do not behave exactly the same, as this will by no means be the only difference they'll encounter.

Actually, FindFirst is not OS dependant, but disk partition dependant.

I.e. searching on FAT disk in Unix should also be case insensitive, because FAT is case-insensitive.
Searching on Ext2(3) or any other disk case-sensitive partition mounted in Windows should also be case-sensitive...

So the ideal solution is to create custom routines: MyFindFirst(
masks, attribs, dir, ForceInsensitive: Boolean);

1) detect if dir searched is case-sensitive
2) do search for all files (*), and check file name match manually.

thanks,
dmitry

Reply by email