Java Path File List nio listFiles(Path directory, String glob)

Here you can find the source of listFiles(Path directory, String glob)

Description

 Glob matcher is explained  java.nio.file.FileSystem#getPathMatcher(String)  getPatchMatcher . 

License

Open Source License

Declaration

public static List<Path> listFiles(Path directory, String glob) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;

import java.nio.file.*;

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**/*from   ww  w  .  j a va  2s. c o m*/
     * <pre>
     * Glob matcher is explained {@link java.nio.file.FileSystem#getPathMatcher(String) getPatchMatcher}.
     *
     * Examples:
     *  "*.{c,h,cpp,hpp,java}"
     *  "*.java"
     * </pre>
     */
    public static List<Path> listFiles(Path directory, String glob) throws IOException {
        List<Path> result = new ArrayList<>();
        try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory, glob)) {
            stream.forEach(result::add);
        } catch (DirectoryIteratorException ex) {
            throw ex.getCause();
        }
        return result;
    }
}

Related

  1. listFiles(Path base, StringBuilder b)
  2. listFiles(Path basePath)
  3. listFiles(Path dir)
  4. listFiles(Path dir, String glob)
  5. listFiles(Path directory)
  6. listFiles(Path path)
  7. listFiles(Path path)
  8. listFiles(Path path, List preorderList)
  9. listFiles(Path path, String glob)