i want to see if a certain directory contains a jpg file. What is the best way (one way) to do this? If the directory didnt have any sub folders it would be easy, but now i want to move through directories to find jpg. For ex:
public static boolean dirHasJpg(File[] files){
//files is the first directory
for(File file : files){
if(file.getName().toLowerCase().endsWith("jpg")){
return true;
}else if(file.isDirectory()){
//move in to a subdirectory.
for (File f2 : file.listFiles()){
if(f2.getName().toLowerCase().endsWith("jpg")) {
return true;
}else if(f2.isDirectory()){
and so on....
}
}
}
}
return false;
}
I understand that is should be a while loop somewhere, but i just cannot figure out how to implement it, something along the lines of.
for(File file : files){
while (file.isDirectory()){
//check that directory and all subdirectories
}
}