目录

Android-遍历文件夹,搜索指定扩展名的文件

目录

Android 遍历文件夹,搜索指定扩展名的文件

private List<String> lstFile = new ArrayList<String>(); //结果 List
2
3public void GetFiles(String Path, String Extension, boolean IsIterative) //搜索目录,扩展名,是否进入子文件夹
4{
5File[] files = new File(Path).listFiles();
6
7for ( int i = 0 ; i < files.length; i++)
8{
9File f = files[i];
10if (f.isFile())
11{
12if (f.getPath().substring(f.getPath().length() - Extension.length()).equals(Extension)) //判断扩展名
13lstFile.add(f.getPath());
14
15if (!IsIterative)
16break ;
17}
18else if (f.isDirectory() && f.getPath().indexOf( "/." ) == - 1 ) //忽略点文件(隐藏文件/文件夹)
19GetFiles(f.getPath(), Extension, IsIterative);
20}
21}