List of utility methods to do Directory to File List
String[] | getAllFilesInFolder(String folder) get All Files In Folder File file = load(folder); if (file != null) { if (file.exists()) { if (file.isDirectory()) { File[] fileList = file.listFiles(); String[] fileNames = new String[fileList.length]; for (int i = 0; i < fileNames.length; i++) { fileNames[i] = fileList[i].getName(); ... |
String[] | getAllFilesInFolderAndSubFolders(String folder) get All Files In Folder And Sub Folders List<File> filesToCheck = new ArrayList<File>(); File file = load(folder); if (file != null) { if (file.exists()) { if (file.isDirectory()) { for (File f : file.listFiles()) { filesToCheck.add(f); boolean foldersInList = true; while (foldersInList) { List<File> remove = new ArrayList<File>(); List<File> toCheck = new ArrayList<File>(); for (File f : filesToCheck) { if (f.isDirectory()) { remove.add(f); for (File fi : f.listFiles()) { toCheck.add(fi); for (File f : toCheck) { filesToCheck.add(f); for (File f : remove) { filesToCheck.remove(f); if (remove.size() == 0) { foldersInList = false; String[] files = new String[filesToCheck.size()]; for (int i = 0; i < files.length; i++) { files[i] = filesToCheck.get(i).getPath(); return files; return new String[] {}; |
File[] | getAllFilesInHierarchy(final String basePath, final FilenameFilter filter) get All Files In Hierarchy return getAllFiles(new File(basePath), filter); |
List | getAllFilesInSubFolder(String base, String ending) Scan the base folder, and return a list of all files with the given name ending
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; |
void | getAllFilesInternal(final File aPath, final FilenameFilter filter, final List get All Files Internal final File[] allFiles = aPath.listFiles(filter); for (int i = 0; i < allFiles.length; i++) { if (allFiles[i].isDirectory()) getAllFilesInternal(allFiles[i], filter, fileList); else fileList.add(allFiles[i]); |
Vector | getAllFilesLeastRecentFirst(File directory) get All Files Least Recent First Vector sortedFileList = new Vector(); if (!directory.exists()) return sortedFileList; File[] allFilesAndDirectories = directory.listFiles(); for (int i = 0; i < allFilesAndDirectories.length; ++i) { File fileToAdd = allFilesAndDirectories[i]; if (!fileToAdd.isFile()) continue; ... |
List | getAllFilesMatching(File srcDir, final String regex) get All Files Matching List<File> foundFiles = new ArrayList<File>(); if (!srcDir.isDirectory()) { if (srcDir.getPath().matches(regex)) { foundFiles.add(srcDir); return foundFiles; return foundFiles; FilenameFilter filenameFiler = new FilenameFilter() { public boolean accept(File dir, String name) { return name.matches(regex); }; }; foundFiles.addAll(Arrays.asList(srcDir.listFiles(filenameFiler))); FileFilter fileFiler = new FileFilter() { public boolean accept(File file) { return file.isDirectory(); }; }; File[] directories = srcDir.listFiles(fileFiler); for (File file : directories) { foundFiles.addAll(getAllFilesMatching(file, regex)); return foundFiles; |
String[] | getAllFilesMatchingThisPatternIgnoreCase(String sDirectoryPath, String sPattern) Returns the set of all files in the given directory, matching the given pattern (ignoring case)
String[] asAllFiles = getAllFiles(sDirectoryPath); Vector vsFiltered = new Vector(); for (int i = 0; i < asAllFiles.length; i++) { if (asAllFiles[i].toLowerCase().matches(sPattern.toLowerCase())) { vsFiltered.add(asAllFiles[i]); String[] asFilteredFiles = new String[vsFiltered.size()]; ... |
List | getAllFilesPresentInFolder(File srcPath) get All Files Present In Folder List fileList = new ArrayList(); if (srcPath.isDirectory()) { String files[] = srcPath.list(); for (int i = 0; i < files.length; i++) { fileList.addAll(getAllFilesPresentInFolder(new File(srcPath, files[i]))); } else { fileList.add(srcPath.getAbsolutePath()); ... |
void | getAllFilesRecursively(File dir, List get All Files Recursively File[] files = dir.listFiles(); if (files == null) { return; int i; for (i = 0; i < files.length; ++i) { if (files[i].isFile()) { filelist.add(files[i]); ... |