I'm trying to check files within a folder to identify the file names that match my regex. My regex matches to incorrectly named files.
So, for example, I have these files in a folder:
-95F Front Anger BW.jpg
-95F.Front.Anger.C.Micro.jpg
-95F.Front.Fear.C.Micro.jpg
-95F.Front.Frown.BW.jpg
The regex should match the first one because correctly named filenames need to have dots instead of whitespaces.
public static void main(String[] args) {
Pattern patternList = Pattern.compile("^(?!(?:((\\d{1,3}([FM])\\."
+ "(Front|Profile|Right)\\.(Anger|Fear|Frown|Smile)\\."
+ "(BW\\.Micro|BW|C\\.Micro|C)))|(\\d{1,3}(F|M)\\."
+ "(Front|Profile|Right)\\.(Neutral|Smile)\\.(C\\.Micro|C|BW\\"
+ ".Micro|BW|HighLight|LowLight|MedLight)\\.(BW\\.Micro|BW|C\\"
+ ".Micro|C))|(\\d{1,3}(F|M)\\.(Selfie1|Selfie2|StudentID)\\."
+ "(C\\.Micro|C|BW\\.Micro|BW)))).*$");
Scanner in = new Scanner(System.in);
System.out.print("Enter base directory: ");
String dir = in.nextLine();
checkFolder(new File(dir), patternList); //EXCEPTION HERE
}
private static void checkFolder(File root, Pattern patternList) {
for(File file : root.listFiles()) //EXCEPTION here
if(file.isFile()){
if(!patternList.matcher(file.getName()).matches())
checkFolder(file, patternList); //EXCEPTION here
else
System.out.println(file);
}
}