/** * Returns the names of the files inside the specified directory. * * @param dirName the name of the directory to start the search from. * @param recurse if {@code true}, we will look in subdirectories. * @return the names of the files inside the specified directory. * @throws IllegalArgumentException if the given directory name does not point to an existing directory. */ public static List<String> fileNamesIn(String dirName, boolean recurse) { File dir = new File(dirName); checkArgument(dir.isDirectory(), "%s is not a directory", quote(dirName)); return fileNamesIn(dir, recurse); }
/** * Returns the names of the files inside the specified directory. * * @param dir the name of the directory to start the search from. * @param recurse if {@code true}, we will look in subdirectories. * @return the names of the files inside the specified directory. */ private static List<String> fileNamesIn(File dir, boolean recurse) { List<String> scriptNames = new ArrayList<>(); File[] existingFiles = dir.listFiles(); if (isNullOrEmpty(existingFiles)) { return scriptNames; } for (File existingFile : existingFiles) { if (existingFile.isDirectory()) { if (recurse) { scriptNames.addAll(fileNamesIn(existingFile, recurse)); } continue; } String filename = existingFile.getAbsolutePath(); if (!scriptNames.contains(filename)) { scriptNames.add(filename); } } return scriptNames; }
/** * Returns the names of the files inside the specified directory. * * @param dirName the name of the directory to start the search from. * @param recurse if {@code true}, we will look in subdirectories. * @return the names of the files inside the specified directory. * @throws IllegalArgumentException if the given directory name does not point to an existing directory. */ public static List<String> fileNamesIn(String dirName, boolean recurse) { File dir = new File(dirName); checkArgument(dir.isDirectory(), "%s is not a directory", quote(dirName)); return fileNamesIn(dir, recurse); }
/** * Returns the names of the files inside the specified directory. * * @param dir the name of the directory to start the search from. * @param recurse if {@code true}, we will look in subdirectories. * @return the names of the files inside the specified directory. */ private static List<String> fileNamesIn(File dir, boolean recurse) { List<String> scriptNames = new ArrayList<>(); File[] existingFiles = dir.listFiles(); if (isNullOrEmpty(existingFiles)) { return scriptNames; } for (File existingFile : existingFiles) { if (existingFile.isDirectory()) { if (recurse) { scriptNames.addAll(fileNamesIn(existingFile, recurse)); } continue; } String filename = existingFile.getAbsolutePath(); if (!scriptNames.contains(filename)) { scriptNames.add(filename); } } return scriptNames; }
/** * Returns the names of the files inside the specified directory. * * @param dirName the name of the directory to start the search from. * @param recurse if {@code true}, we will look in subdirectories. * @return the names of the files inside the specified directory. * @throws IllegalArgumentException if the given directory name does not point to an existing directory. */ public static List<String> fileNamesIn(String dirName, boolean recurse) { File dir = new File(dirName); if (!dir.isDirectory()) { throw new IllegalArgumentException(format("%s is not a directory", quote(dirName))); } return fileNamesIn(dir, recurse); }
/** * Returns the names of the files inside the specified directory. * * @param dir the name of the directory to start the search from. * @param recurse if {@code true}, we will look in subdirectories. * @return the names of the files inside the specified directory. */ private static List<String> fileNamesIn(File dir, boolean recurse) { List<String> scriptNames = new ArrayList<String>(); File[] existingFiles = dir.listFiles(); if (isNullOrEmpty(existingFiles)) { return scriptNames; } for (File existingFile : existingFiles) { if (existingFile.isDirectory()) { if (recurse) { scriptNames.addAll(fileNamesIn(existingFile, recurse)); } continue; } String filename = existingFile.getAbsolutePath(); if (!scriptNames.contains(filename)) { scriptNames.add(filename); } } return scriptNames; }