[英]Android SD card directory folders name list
How can I get names of all folders (not files) in specific directory on SD card? 如何获取SD卡上特定目录中所有文件夹(不是文件)的名称? For example all subfolders names in
/sdcard/first_level_folder/...
. 例如,
/sdcard/first_level_folder/...
所有子文件夹名称。
I need folder name, so I can pass complete path (string) to the method which will then compress (zip) it. 我需要文件夹名称,所以我可以将完整路径(字符串)传递给方法,然后压缩(zip)它。
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. 步骤1:使用
Environment.getExternalStorageDirectory()
获取外部存储的根目录。 /sdcard/
is incorrect on most devices. /sdcard/
在大多数设备上都不正确。
Step #2: Use the appropriate File
constructor to create the File
object pointing to your desired directory inside external storage. 步骤2:使用适当的
File
构造函数创建指向外部存储内所需目录的File
对象。
Step #3: Use Java I/O to find what is in that directory. 步骤#3:使用Java I / O查找该目录中的内容。
Well you can use something like: 那么你可以使用类似的东西:
File file[] = Environment.getExternalStorageDirectory().listFiles();
for (File f : file)
{
if (f.isDirectory()) { ... do stuff }
}
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. 步骤1:使用
Environment.getExternalStorageDirectory()
获取外部存储的根目录。 /sdcard/
is incorrect on most devices. /sdcard/
在大多数设备上都不正确。
Step #2: Use the appropriate File
constructor to create the File
object pointing to your desired directory inside external storage. 步骤2:使用适当的
File
构造函数创建指向外部存储内所需目录的File
对象。
Step #3: Use Java I/O to find what is in that directory. 步骤#3:使用Java I / O查找该目录中的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.