开发者

Android SD card directory folders name list

How 开发者_如何学Pythoncan 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.


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);


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.


Well you can use something like:

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


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


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";


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);
        }


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


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

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜