I am working on Unix, which uses case sensitive filenames and need a way to access them in a case-insensitive manner.
Specifically, at time the program needs to get into a /images directory under a project folder. But because this directory is created manually by the user, it may sometimes be named Images, IMAGES, iMaGes…you get the idea.
Given that there is guaranteed to be only one images directory in any project folder, how can I access this directly without getting the entire directory list and looping through it?
There is no other way then reading the full list of directory names and check each and everyone if it matches your pattern.
You can hide it by using a
FilenameFilterthat filters all folder names that don’t match your pattern (iaw, any folder, whose lowercased name is equal toimages). This may be a better approach, because it will return all candidates (iaw:./Images,./imaGes,./IMAGESif you have creative users that place more then one image folder 😉 )