List of utility methods to do Path File List nio
List | listFiles(Path directory, String glob)Glob matcher is explained java.nio.file.FileSystem#getPathMatcher(String) getPatchMatcher .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; |
List | listFiles(Path path) list Files Deque<Path> stack = new ArrayDeque<>(); final List<Path> files = new LinkedList<>(); stack.push(path); while (!stack.isEmpty()) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(stack.pop())) { for (Path entry : stream) { if (Files.isDirectory(entry)) { stack.push(entry); ... |
List | listFiles(Path path) list Files final List<Path> result = new ArrayList<>(); Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { result.add(file); return FileVisitResult.CONTINUE; }); ... |
void | listFiles(Path path, List list Files preorderList.add(path); File[] listFiles = path.toFile().listFiles(); if (listFiles != null) for (File child : listFiles) { listFiles(child.toPath(), preorderList); |
List | listFiles(Path path, String glob) list Files final PathMatcher matcher = path.getFileSystem().getPathMatcher("glob:" + glob); final DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() { @Override public boolean accept(Path entry) throws IOException { return Files.isDirectory(entry) || matcher.matches(entry.getFileName()); }; List<Path> result = new ArrayList<Path>(); ... |
List | listFilesRecursively(Path dir, final DirectoryStream.Filter list Files Recursively final List<Path> files = new ArrayList<>(); Files.walkFileTree(dir, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (filter.accept(file)) files.add(file); return recursive ? FileVisitResult.CONTINUE : FileVisitResult.SKIP_SUBTREE; }); return files; |
List | listFoldersInFolder2(String path) list Folders In Folder List<String> filesInFolder = new ArrayList<String>(); Path pathP = Paths.get(path); try { DirectoryStream<Path> rootStream = Files.newDirectoryStream(pathP); for (Path folderName : rootStream) { filesInFolder.add(folderName.getFileName().toString()); } catch (IOException e) { ... |
Set | listOfWords(String filePath) Reads the file from the given path String path = Paths.get(".").toAbsolutePath().normalize().toString(); try (Scanner scanner = new Scanner(new File(path + "/" + filePath))) { while (scanner.hasNext()) { words.add(scanner.nextLine()); return words; |
Iterable | listSteps(Path scenarioDirectory) Lists all scenario steps within the given directory path. if (!Files.isDirectory(scenarioDirectory)) { throw new IllegalArgumentException( String.format("Path '%s' is not a directory.", scenarioDirectory.toAbsolutePath())); File[] list = scenarioDirectory.toFile().listFiles(STEP_FILTER); if (list == null || list.length == 0) { throw new IllegalStateException( String.format("No test steps found in directory: '%s'", scenarioDirectory.toAbsolutePath())); ... |
List | loadDataFilesList(String prefix, Path bwcIndicesPath) load Data Files List List<String> indexes = new ArrayList<>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(bwcIndicesPath, prefix + "-*.zip")) { for (Path path : stream) { indexes.add(path.getFileName().toString()); Collections.sort(indexes); return indexes; ... |