List of utility methods to do Directory Search
Vector | find(File pDirectory, String pRegex) find all files in pDirectory and its sub directories whose absolute path matches pRegex Vector<File> lReturn = new Vector<File>(); lReturn = find(lReturn, pDirectory, new RegExpFileFilter(pRegex)); return lReturn; |
File[] | findFiles(File dir, FileFilter filter) Finds all files (non-recursively) in a directory based on the FileFilter. if (!dir.exists()) { throw new FileNotFoundException("Directory " + dir + " does not exist."); if (!dir.isDirectory()) { throw new FileNotFoundException("File " + dir + " is not a directory."); ArrayList<File> files = new ArrayList<File>(); File[] allFiles = dir.listFiles(); if (allFiles != null && allFiles.length > 0) { for (File f : allFiles) { if (f.isFile()) { if (filter.accept(f)) { files.add(f); File[] r = files.toArray(new File[0]); Arrays.sort(r); return r; |
String | recursiveSearch(java.io.File dir, String fileName) Recursive method for searching file path. for (String name : dir.list()) { java.io.File file = new java.io.File(dir.getAbsolutePath() + "/" + name); if (name.compareTo(fileName) == 0) return file.getAbsolutePath(); if (file.isDirectory()) { String filePath = recursiveSearch(file, fileName); if (filePath != null) ... |