java的写法 /** * * @param location * @param nameList保存结果的! */ public void listDict(String location, List<String> nameList) { File fileList = new File(location); if (fileList.isDirectory()) { File[] files = fileList.listFiles(); for (File f : files) { if (f.isDirectory()) { listDict(f.getPath(), nameList); // 递归 } else { String fullpath = f.getPath(); String name = f.getName(); String ext = name.substring(name.indexOf(".") + 1); // 文件扩展名 if ("dic".equalsIgnoreCase(ext)) { // 过滤只要dic的文件 nameList.add(fullpath); } } } } } php的写法 待补充