[fpc-pascal] Case insensitive FindFirst and friends

Jonas Maebe jonas.maebe at elis.ugent.be
Mon May 18 10:53:26 CEST 2009


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

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



More information about the fpc-pascal mailing list