Nayan Sonthalia Nayan Sonthalia - 6 months ago 24
Java Question

Regular expression and AwkFilenameFilter

We have a folder where we dump lot of files. Our program needs to read one of the specific files with the latest version. The file name would be something like "2016-03-04-12-46-48_ABC_123456_1.xml".

Insted of reading all the files and then iterating to find the exact file i have used following code with a regular expression

File folder = new File("C:\\some_folder")
folder.listFiles((FilenameFilter) new AwkFilenameFilter("(\\d){4}-(\\d){2}-(\\d){2}-(\\d){2}-(\\d){2}-(\\d){2}_ABC_" + <ID_String> +"_(\\d){1,2}"))


But for some reason the reqular expression is not working. Can someone please help with this?

AKS AKS
Answer

It seems you are missing the file extension in the regex:

(\\d){4}-(\\d){2}-(\\d){2}-(\\d){2}-(\\d){2}-(\\d){2}_ABC_" + <ID_String> +"_(\\d){1,2}\\.xml
Comments