如何挑选来自Android的文件夹和子文件夹中的所有文件?
问题描述:
可能重复:结果
递归列出的Java 文件
我已经创建了一个名为SD卡幻灯片一个文件夹。此文件夹中我创建两个文件夹即文件夹1和文件夹2。这两个文件夹再分为每两个子文件夹。我现在的储蓄从画廊的一些图片到这些子文件夹。
I have created one folder named SlideShow in sdcard. Inside this folder i created two folders namely folder1 and folder2. These two folders further divided into two subfolders each. I am saving some images from gallery into these subfolders.
任何人都建议我如何列出所有的幻灯片文件,包括文件夹和子文件夹??图像
答
我认为你可以使用这样recrusive功能:您可以通过这个例子帮助
I think that you can use recrusive function like this: you can take help through this example
public List<String> images=new ArrayList<String>();
public recursiveFunction(File dirPath) {
File f = new File(dirPath);
File[] files = f.listFiles();
for(int i=0;i,**files.length - 1**;i++)
{
if(files[position].isFile())
{
int mid= files[position].getName().lastIndexOf(".");
String ext=files[position].getName().substring(mid+1,files[position].getName().length());
if( ext.equalsIgnoreCase("jpg")
|| ext.equalsIgnoreCase("png")
|| ext.equalsIgnoreCase("jpeg")
|| ext.equalsIgnoreCase("gif"))
{
images.add(files[position].getAbsoluteFile();
}
}
else
recursiveFunction(files[position].getAbsoluteFile());
}
}
在图像列出你有你的所有图像。
in images list you have your all images.