Here you can find the source of getAllFilesInSubFolder(String base, String ending)
base
folder, and return a list of all files with the given name ending
Parameter | Description |
---|---|
base | a parameter |
ending | a parameter |
public static List<File> getAllFilesInSubFolder(String base, String ending) throws IllegalArgumentException
//package com.java2s; /**//from w ww . j av a2s. c o m * Copyright (C) 2011,2012 Gordon Fraser, Andrea Arcuri and EvoSuite * contributors * * This file is part of EvoSuite. * * EvoSuite is free software: you can redistribute it and/or modify it under the * terms of the GNU Public License as published by the Free Software Foundation, * either version 3 of the License, or (at your option) any later version. * * EvoSuite is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Public License for more details. * * You should have received a copy of the GNU Public License along with * EvoSuite. If not, see <http://www.gnu.org/licenses/>. */ import java.io.File; import java.util.LinkedList; import java.util.List; public class Main { /** * Scan the <code>base</code> folder, and return a list of all files with the given name <code>ending</code> * * @param base * @param ending * @return */ public static List<File> getAllFilesInSubFolder(String base, String ending) throws IllegalArgumentException { File dir = new File(base); if (!dir.exists() || !dir.isDirectory()) { throw new IllegalArgumentException("Invalid folder " + base); } List<File> files = new LinkedList<File>(); recursiveFileSearch(files, dir, ending); return files; } private static void recursiveFileSearch(List<File> files, File dir, String ending) { for (File file : dir.listFiles()) { if (file.isDirectory()) { recursiveFileSearch(files, file, ending); } else { if (file.getName().endsWith(ending)) { files.add(file); } } } } }