List of utility methods to do Path File List nio
Set | listChildren(Path directory) list Children return listChildren(directory, DEFAULT_GLOB);
|
List | listChildren(Path directory) Traverse a directory an return children files with depth 0. return listChildren(directory, "*"); |
List | listDir(Path dir) list Dir List<Path> contents = new LinkedList<>(); try (Stream<Path> list = Files.list(dir)) { list.forEach(contents::add); return contents; |
String[] | listDirsRecursive(String pathStr, String pattern, int maxDepth) list Dirs Recursive final PathMatcher matcher = FileSystems.getDefault().getPathMatcher(pattern); Path path = Paths.get(pathStr); final List<String> files = new ArrayList<>(); if (maxDepth == -1) { maxDepth = Integer.MAX_VALUE; try { Files.walkFileTree(path, Collections.<FileVisitOption>emptySet(), maxDepth, ... |
List | listFiles(final Path path) list Files List<Path> paths = new ArrayList<>(); listFiles(path, paths); return paths; |
void | listFiles(Path base, StringBuilder b) list Files try (DirectoryStream<Path> stream = Files.newDirectoryStream(base)) { for (Path file : stream) { if (Files.isDirectory(file)) { listFiles(file, b); } else { b.append(file.toAbsolutePath() + ", "); } catch (IOException ioe) { return; |
List | listFiles(Path basePath) Returns the list of files in a folder using NIO API. return listFiles(basePath, 1);
|
List | listFiles(Path dir) list Files List<Path> result = new ArrayList<>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { for (Path entry : stream) { result.add(entry); } catch (DirectoryIteratorException ex) { throw ex.getCause(); return result; |
List | listFiles(Path dir, String glob) list Files Preconditions.checkArgument(Files.isDirectory(dir), "%s is not a directory", dir); List<String> globLevels; if (glob == null || glob.isEmpty()) { globLevels = Collections.singletonList("*"); } else { globLevels = Arrays.asList(glob.split("/")); Preconditions.checkState(!globLevels.isEmpty()); ... |
List | listFiles(Path directory) Returns a List of file paths of the child elements of the specified directory. List<Path> files = new ArrayList<>(); try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(directory)) { directoryStream.forEach(files::add); return files; |