I have to get a file from a PDF files directory. I have problem that I haven’t a field to concant all data to find the file.
Here’s an example:
File name:
Comp_20120619_170310_2_632128_FC_A_8_23903.pdf
File name generate:
Comp_20120619_--------_2_632128_FC_A_8_23903.pdf
I dont’ have the field "--------" to make file COMPLETE name.
I’m trying with File.list but I cannot find the correct file.
You can define a FilenameFilter to match against the filenames, and return true if the filename matches what you’re looking for.
The
listFiles()method returns an array of File objects. This makes sense, because there might be more than one file that matches the pattern (in theory at least, albeit not necessarily in your system).I’ve used a regular expression to match the filename, using
[^_]*to match the section you’re not sure about. However, you can use any function that will return a boolean if the filename matches. For example, you could usestartsWithandendsWithinstead of a regular expression.