Java Utililty Methods Path File List nio

List of utility methods to do Path File List nio

Description

The list of methods to do Path File List nio are organized into topic(s).

Method

SetlistChildren(Path directory)
list Children
return listChildren(directory, DEFAULT_GLOB);
ListlistChildren(Path directory)
Traverse a directory an return children files with depth 0.
return listChildren(directory, "*");
ListlistDir(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,
...
ListlistFiles(final Path path)
list Files
List<Path> paths = new ArrayList<>();
listFiles(path, paths);
return paths;
voidlistFiles(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;
ListlistFiles(Path basePath)
Returns the list of files in a folder using NIO API.
return listFiles(basePath, 1);
ListlistFiles(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;
ListlistFiles(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());
...
ListlistFiles(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;