Android SD Card Directory Folder List

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

I need a folder name, so I can pass the full path (string) to a method, which then compresses (zip) it.

Thanks.

+4
source share
6 answers

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

Step # 2: use the appropriate File constructor to create a File object that points to the desired directory inside the external storage.

Step # 3: use Java I / O to find what is in this directory.

+8
source

I think you are looking

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

Well, you can use something like:

 File file[] = Environment.getExternalStorageDirectory().listFiles(); for (File f : file) { if (f.isDirectory()) { ... do stuff } } 
+3
source

Well, this is a java related question. Mark this one out.

To access the sdcard folder name:

 File extStore = Environment.getExternalStorageDirectory(); String SD_PATH = extStore.getAbsolutePath()+"your sd folder here"; 
+2
source
 File file=new File("/mnt/sdcard/"); File[] list = file.listFiles(); int count = 0; for (File f: list){ String name = f.getName(); if (name.endsWith(".jpg") || name.endsWith(".mp3") || name.endsWith(".some media extention")) count++; System.out.println("170 " + count); } 
0
source
 File file[] = Environment.getExternalStorageDirectory().listFiles(); for (File f : file) { if (f.isDirectory()) { // ... do stuff } } 

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

Step # 2: Use the appropriate File constructor to create a File object that points to the desired directory inside the external storage.

Step # 3: use Java I / O to find what is in this directory.

-2
source

All Articles