List of utility methods to do Path File List nio
List | getDirectoryList(Path basePath) Read directory content. final List<Path> directoryNames = new ArrayList<Path>(); if (Files.exists(basePath) && Files.isDirectory(basePath)) { DirectoryStream<Path> files = null; try { files = Files.newDirectoryStream(basePath); for (Path path : files) { if (Files.isDirectory(path)) { directoryNames.add(path.toAbsolutePath()); ... |
List | getPreorderList(Path root) Get a list of all files and subfiles in the root directory. List<Path> allFiles = new ArrayList<Path>(); listFiles(root, allFiles); return allFiles; |
List | getSortedPathList(final Path dir, final boolean dirsFirst) Supposed to be faster than getting the list and sorting it. if (!Files.isDirectory(dir)) return null; final Map<String, Path> files = new TreeMap<String, Path>(); final Map<String, Path> dirs = new TreeMap<String, Path>(); try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(dir)) { for (Path file : directoryStream) { if (dirsFirst && Files.isDirectory(file)) { dirs.put(file.getFileName().toString(), file); ... |
Set | getTables(final List get Tables final Set<String> tables = new HashSet<String>(); for (final Path dir : d1) { try (DirectoryStream<Path> listing = Files.newDirectoryStream(dir)) { for (final Path table : listing) { if (Files.isDirectory(table)) { tables.add(table.getFileName().toString()); return tables; |
boolean | isBlackListedDirectory(Path path) is Black Listed Directory for (final String black : DIR_BLACKLIST) { if (path.toAbsolutePath().toString().contains(black)) { return true; return false; |
boolean | isPlaylistFile(Path testFile) is Playlist File String fileName = testFile.getFileName().toString(); if (!Files.exists(testFile)) { return false; } else if (!Files.isRegularFile(testFile)) { return false; } else if (fileName.lastIndexOf(".") == -1 || fileName.lastIndexOf(".") == 0) { return false; String testExtension = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase(); for (String playlistExtension : playlistExtStrings) { if (playlistExtension.toLowerCase().equals(testExtension)) { return true; return false; |
List | list(final Path directory) A list of the entries in the directory. try (final Stream<Path> entries = Files.list(directory)) { return entries.collect(Collectors.toList()); |
String[] | list(Path basePath) list if (basePath == null) return null; List<String> files = new ArrayList<>(); Files.walkFileTree(basePath, EnumSet.noneOf(FileVisitOption.class), 1, new FileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { return FileVisitResult.CONTINUE; @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { files.add(file.toAbsolutePath().toString()); return FileVisitResult.CONTINUE; @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return FileVisitResult.CONTINUE; @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return FileVisitResult.CONTINUE; }); return files.toArray(new String[files.size()]); |
List | listChildren(Path dir) Gets children paths from the give directory. return listChildren(dir, null);
|
List | listChildren(Path dir, boolean searchDirectory) Gets list of children folder or files for dir, according to searchDirectory param. DirectoryStream.Filter<Path> filter = searchDirectory ? Files::isDirectory : Files::isRegularFile; try (DirectoryStream<Path> ds = Files.newDirectoryStream(dir, filter)) { return StreamSupport.stream(ds.spliterator(), false).collect(Collectors.toList()); |