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