Android SD card directory folders name list

18,844

Solution 1

Step #1: Use Environment.getExternalStorageDirectory() to get the root of external storage. /sdcard/ is incorrect on most devices.

Step #2: Use the appropriate File constructor to create the File object pointing to your desired directory inside external storage.

Step #3: Use Java I/O to find what is in that directory.

Solution 2

I think what you are looking for is

File dir = new File("directoryPath");
FileFilter fileFilter = new FileFilter() {
    public boolean accept(File file) {
        return file.isDirectory();
    }
};
File[] files = dir.listFiles(fileFilter);

Solution 3

Well you can use something like:

File file[] = Environment.getExternalStorageDirectory().listFiles();  


for (File f : file)
{
    if (f.isDirectory()) { ... do stuff }
}

Solution 4

well this is a java related question. Check this out.

To get access to the sdcard folder name :

File extStore = Environment.getExternalStorageDirectory();
String SD_PATH = extStore.getAbsolutePath()+"your sd folder here";
Share:
18,844
waxi
Author by

waxi

Updated on June 26, 2022

Comments

  • waxi
    waxi about 2 years

    How can I get names of all folders (not files) in specific directory on SD card? For example all subfolders names in /sdcard/first_level_folder/....

    I need folder name, so I can pass complete path (string) to the method which will then compress (zip) it.

    Thanks.

    • waxi
      waxi almost 13 years
      thanks everyone for answers... problem solved :)
    • Erum
      Erum over 9 years
      can u pls tell me how u resolve your issue ?
  • Cerbrus
    Cerbrus almost 10 years
    Your answer appeared in the "Low quality" review queue, because it only contains a block of code. Please explain what the code does, and why it works, to improve the quality of your answer.
  • Melvin
    Melvin almost 10 years
    Step #1: Use Environment.getExternalStorageDirectory() to get the root of external storage. /sdcard/ is incorrect on most devices. Step #2: Use the appropriate File constructor to create the File object pointing to your desired directory inside external storage. Step #3: Use Java I/O to find what is in that directory.
  • Cerbrus
    Cerbrus almost 10 years
    ... In the answer itself. Not in the comments.