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";
![waxi](https://i.stack.imgur.com/HU076.jpg?s=256&g=1)
Author by
waxi
Updated on June 26, 2022Comments
-
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 almost 13 yearsthanks everyone for answers... problem solved :)
-
Erum over 9 yearscan u pls tell me how u resolve your issue ?
-
-
Cerbrus almost 10 yearsYour 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 almost 10 yearsStep #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 almost 10 years... In the answer itself. Not in the comments.