Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get filenames from a directory in Android

I want to populate a spinner with the filenames of files found on the SD card with specific extensions. I can get it thus far to populate the spinner with the correct files, but the path is shown as well.

Can anyone tell me how to only get the filename of a specific file in a directory on the SD card?

like image 521
user1145581 Avatar asked Jan 12 '12 13:01

user1145581


1 Answers

File sdCardRoot = Environment.getExternalStorageDirectory();
File yourDir = new File(sdCardRoot, "path");
for (File f : yourDir.listFiles()) {
    if (f.isFile())
        String name = f.getName();
        // Do your stuff
}

Have a look at Environment page for more info.

like image 155
Siva Charan Avatar answered Oct 19 '22 20:10

Siva Charan