Java Path File Name nio getFilesFromDirectory(Path directory, List filenames)

Here you can find the source of getFilesFromDirectory(Path directory, List filenames)

Description

get Files From Directory

License

Apache License

Declaration

private static void getFilesFromDirectory(Path directory, List<String> filenames) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.IOException;
import java.nio.file.DirectoryIteratorException;
import java.nio.file.DirectoryStream;

import java.nio.file.Files;
import java.nio.file.Path;

import java.util.List;

public class Main {
    private static void getFilesFromDirectory(Path directory, List<String> filenames) {
        try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory)) {
            for (Path file : stream) {
                //System.out.println(file.getFileName() + ":"+file.getFileName().toString().endsWith("/"));
                if (file.getFileName().toString().endsWith("/")) {
                    getFilesFromDirectory(file, filenames);
                } else {
                    // System.out.println(file.getFileName());
                    filenames.add(directory.toString() + file.getFileName() + "");
                    //               filenames.add(file.getFileName() + "");
                }/*from   w  w  w. j a  v a 2  s. c o m*/
            }
        } catch (IOException | DirectoryIteratorException x) {
            // IOException can never be thrown by the iteration.
            // In this snippet, it can only be thrown by
            // newDirectoryStream.
            System.err.println(x);
        }
    }
}

Related

  1. getFileNames(List fileNames, Path dir, String sFilter)
  2. getFileNameWithoutExt(final Path file)
  3. getFilePath(String dirName)
  4. getFilePathName(Path filePath)
  5. getFilePathsInFolder(String sensorName)
  6. getFormattedDisplayName(String fileDisplayName, Path path, String baseDir)
  7. getFullFileName(Path path)
  8. getFullPath(String basePath, String fileName)
  9. getIndexPath(String rootDirectory, String basename)