JAVA ANDROID - get list files of a folder

15,791

this method will give you a list containing a list of dir folders and also sub folders:

public void listf(String directoryName, ArrayList<File> files) {
File directory = new File(directoryName);

// get all the files from a directory
File[] fList = directory.listFiles();
for (File file : fList) {
    if (file.isFile()) {
        files.add(file);
    } else if (file.isDirectory()) {
        listf(file.getAbsolutePath(), files);
    }
}
}
Share:
15,791
Francisco
Author by

Francisco

Updated on June 11, 2022

Comments

  • Francisco
    Francisco almost 2 years

    I want to display images of different folders in a GridView, but I don't know what I need to do for get a list with the name of files that are inside a folder in drawable.

  • Francisco
    Francisco over 10 years
    I see this in another post, but how i can put de directory "drawable" that is in the project?
  • Mostafa Jamareh
    Mostafa Jamareh over 10 years
    your dir must be something like this: res/drawable