Example usage for java.nio.file Files newDirectoryStream

List of usage examples for java.nio.file Files newDirectoryStream

Introduction

In this page you can find the example usage for java.nio.file Files newDirectoryStream.

Prototype

public static DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter)
        throws IOException 

Source Link

Document

Opens a directory, returning a DirectoryStream to iterate over the entries in the directory.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {

    Path dir = Paths.get("C:/");

    DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "*.exe");
    for (Path entry : stream) {
        System.out.println(entry.getFileName());
    }/*  ww  w  .  j a v a  2s  .c  o m*/
}

From source file:Test.java

public static void main(String[] args) throws Exception {

    Path dir = Paths.get("C:/workspace/java");

    DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "*.properties");
    for (Path entry : stream) {
        System.out.println(entry.getFileName());
    }/*  w w w  .ja v  a2 s .  c  o  m*/
}

From source file:Test.java

public static void main(String[] args) {
    Path directory = Paths.get("C:/Program Files/Java/jdk1.7.0/bin");
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(directory, "java*.exe")) {
        for (Path file : directoryStream) {
            System.out.println(file.getFileName());
        }//  w  w w  .j  av a  2s. c o m
    } catch (IOException | DirectoryIteratorException ex) {
        ex.printStackTrace();
    }

}

From source file:Test.java

public static void main(String[] args) {
    Path directory = Paths.get("C:/Program Files/Java/jdk1.7.0/bin");
    PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:java?.exe");
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(directory, "java*.exe")) {
        for (Path file : directoryStream) {
            if (pathMatcher.matches(file.getFileName())) {
                System.out.println(file.getFileName());
            }/*from  ww  w  .ja va  2  s.  co m*/
        }
    } catch (IOException | DirectoryIteratorException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {
    DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() {
        public boolean accept(Path file) throws IOException {
            return (Files.isHidden(file));
        }//from   w  w w.java 2s .co m
    };
    Path directory = Paths.get("C:/Windows");
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(directory, filter)) {
        for (Path file : directoryStream) {
            System.out.println(file.getFileName());
        }
    } catch (IOException | DirectoryIteratorException ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {

    Path path = Paths.get("C:/tutorial/Java/JavaFX");

    DirectoryStream.Filter<Path> dir_filter = new DirectoryStream.Filter<Path>() {
        public boolean accept(Path path) throws IOException {
            return (Files.isDirectory(path, NOFOLLOW_LINKS));
        }//from w w  w. j  a v a2 s.  com
    };

    try (DirectoryStream<Path> ds = Files.newDirectoryStream(path, dir_filter)) {
        for (Path file : ds) {
            System.out.println(file.getFileName());
        }
    } catch (IOException e) {
        System.err.println(e);
    }

}

From source file:hk.mcc.utils.applog2es.Main.java

/**
 * @param args the command line arguments
 *//*from  w  ww.  ja v  a 2s.  c o  m*/
public static void main(String[] args) throws Exception {
    String pathString = "G:\\tmp\\Archive20160902";
    Path path = Paths.get(pathString);
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(path, "app*.log")) {
        for (Path entry : stream) {
            List<AppLog> appLogs = new ArrayList<>();
            try (AppLogParser appLogParser = new AppLogParser(Files.newInputStream(entry))) {
                AppLog nextLog = appLogParser.nextLog();
                while (nextLog != null) {
                    //    System.out.println(nextLog);
                    nextLog = appLogParser.nextLog();
                    appLogs.add(nextLog);
                }

                post2ES(appLogs);
            } catch (IOException ex) {
                Logger.getLogger(AppLogParser.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

}

From source file:com.ignorelist.kassandra.steam.scraper.LibraryScanner.java

public static Set<Long> findGames(Path path) throws IOException {
    Set<Long> gameIds = new HashSet<>();
    DirectoryStream<Path> directoryStream = null;
    try {//from  w  w w  .ja v a  2  s .c o m
        directoryStream = Files.newDirectoryStream(path, new DirectoryStream.Filter<Path>() {

            @Override
            public boolean accept(Path entry) throws IOException {
                return Files.isRegularFile(entry);
            }
        });
        for (Path f : directoryStream) {
            final String fileName = f.getFileName().toString();
            Matcher matcher = PATTERN.matcher(fileName);
            if (matcher.matches()) {
                gameIds.add(Long.parseLong(matcher.group(1)));
            }
        }
        return gameIds;
    } finally {
        IOUtils.closeQuietly(directoryStream);
    }
}

From source file:de.dal33t.powerfolder.util.AddLicenseHeader.java

public static void addLicInfoToDir(Path dir) {
    Filter<Path> filter = new Filter<Path>() {
        @Override//from ww  w. j av  a 2 s .  c o  m
        public boolean accept(Path entry) {
            return entry.getFileName().toString().endsWith(".java");
        }
    };

    try (DirectoryStream<Path> javas = Files.newDirectoryStream(dir, filter)) {
        for (Path file : javas) {
            addLicInfo(file);
        }
    } catch (IOException ioe) {
        // TODO:
    }

    filter = new Filter<Path>() {
        @Override
        public boolean accept(Path entry) {
            return Files.isDirectory(entry);
        }
    };

    try (DirectoryStream<Path> subDirs = Files.newDirectoryStream(dir, filter)) {
        for (Path subDir : subDirs) {
            addLicInfoToDir(subDir);
        }
    } catch (IOException ioe) {
        // TODO:
    }
}

From source file:com.pixlabs.web.utils.Mp3Finder.java

/**
 * @param path Path of the directory that should be looked into.
 * @return a linkedlist containing all the Mp3 files found in the directory.
 * @throws NotDirectoryException The given path was not a directory.
 *//* w ww . java2 s  .c o m*/

public static LinkedList<Mp3FileAdvanced> mp3InDirectory(Path path) throws NotDirectoryException {
    if (!Files.isDirectory(path))
        throw new NotDirectoryException("The chosen path does not represent a directory");
    LinkedList<Mp3FileAdvanced> list = new LinkedList<>();
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(path, "*.mp3")) {
        for (Path entry : stream) {
            //       if(!entry.startsWith("."))
            list.add(new Mp3FileAdvanced(entry.toFile()));
        }

    } catch (IOException | UnsupportedTagException | InvalidDataException e) {
        e.printStackTrace();
    }
    return list;
}