I am searching for an efficient way to test if files exists which have a file-name of a certain pattern.
Examples using wildcards:
- ????.*
- ???????.*
- *.png
- *.jpg
Examples using regular expressions:
- [012]{4}.*
- [012]{7}.*
The problem is that the directory I have to test contains up to 500.000 files. The only way I know to perform such tests is to use the methods of the File class:
String[] list() String[] list(FilenameFilter filter) File[] listFiles() File[] listFiles(FileFilter filter) File[] listFiles(FilenameFilter filter) The problem is that basically they are all implemented the same way: First the call list() for getting all available files and the they apply the filter on it.
Please imagine yourself what happens if we want to apply this on a folder containing 500.000 files...
If there any alternative in Java for retrieving the filename of the first matching file regarding files in a directory without having to enumerate all of them?
If JNI is the only option - is there a library can do this that comes with pre-compiled binaries for the six major platforms (Linux, Windows and OSX each 32 and 64 bit)?