Android-遍历文件夹,搜索指定扩展名的文件
约 150 字
预计阅读 1 分钟
Android 遍历文件夹,搜索指定扩展名的文件
|
---|
private List<String> lstFile = new ArrayList<String>(); //结果 List |
| |
---|
3 | public void GetFiles(String Path, String Extension, boolean IsIterative) //搜索目录,扩展名,是否进入子文件夹 |
| |
---|
5 | File[] files = new File(Path).listFiles(); |
| |
---|
7 | for ( int i = 0 ; i < files.length; i++) |
| |
---|
12 | if (f.getPath().substring(f.getPath().length() - Extension.length()).equals(Extension)) //判断扩展名 |
| |
---|
13 | lstFile.add(f.getPath()); |
| |
---|
18 | else if (f.isDirectory() && f.getPath().indexOf( "/." ) == - 1 ) //忽略点文件(隐藏文件/文件夹) |
| |
---|
19 | GetFiles(f.getPath(), Extension, IsIterative); |