I have a method which iterates over a supplied array of directories and prints out all of the audio files in there. I want to add a counter to get a total of all audio files found from the total scan. At the moment, whenever the
if(file.isDirectory()){new MusicGetter(path).lookup();}
condition is met and it moves onto a new folder, the total is reset.
Thanks for any help :)
full method:
public void lookup()
{
File folder = new File(c);
//File[] listOfFiles = folder.listFiles();
int count = 0;
if(folder.listFiles() == null)
{
return;
}
for (File file : folder.listFiles())
{
String path = file.getPath();
//in each directory print out the audio files
if(path.contains(".mp3") || path.contains(".wav") || path.contains(".flac") || path.contains(".m4a") || path.contains(".ogg") || path.contains(".wma"))
{
System.out.println(path);
count++;
}
//call method again if the file is a directory
if (file.isDirectory())
{
new MusicGetter(path).lookup();
}
}
System.out.println("count is" + count);
}