FilenameFilter through subdirectories in Java

rgppimm

New Member
I am creating an android app that will search through a directory, grab all files that end with .mp3 and add them to an array list. I have the starting point at /sdcard/, but not all of the music files are directly in that path. The rest are in /sdcard/Music/(artist)/.... I am trying to get my FilenameFilter to continue through the subdirectories and then add it to the list. Here's the code that I'm working with:\[code\]class Mp3Filter implements FilenameFilter{public boolean accept(File dir, String name){ return(name.endsWith(".mp3")&& dir.isDirectory());}}private void updatePlaylist() { File home = new File(SD_PATH); if(home.listFiles(new Mp3Filter()).length>0){ for(File file : home.listFiles(new Mp3Filter())){ songs.add(file.getName());` } ArrayAdapter<String> songList = new ArrayAdapter<String>(this,R.layout.song_item, songs); setListAdapter(songList); } }\[/code\]
 
Back
Top