// 获得某个文件夹folderPath下面某种文件后缀fileType的所有文件名
public static List<String> getFileNamesInFolder(String folderPath,
String fileType) {
File folder = new File(folderPath);
File[] files = folder.listFiles();
List<String> fileNames = new ArrayList<String>();
for (int i = 0; i < files.length; ++i) {
File file = files[i];
if (file.isFile()) {
String[] str = file.getPath().split("\.");
if (str[str.length - 1].equals(fileType)) { // 分割完后查最后的分割单元
fileNames.add(file.getName().split("\.")[0]);
}
}
}
return fileNames;
}
// 递归查询当前可以使用的默认文件名Test的number
public static int calFileNameIndex(List<String> nameList, int currentNum) {
String str = "Test";
for (int i = 0; i < nameList.size(); ++i) {
if (nameList.get(i).toString().equals(str + currentNum)) {
nameList.remove(i);
currentNum = calFileNameIndex(nameList, ++currentNum);
break;
}
}
return currentNum;
}