Java Path File Name nio getFileNames(List fileNames, Path dir)

Here you can find the source of getFileNames(List fileNames, Path dir)

Description

get File Names

License

Open Source License

Declaration

public static List<String> getFileNames(List<String> fileNames, Path dir) 

Method Source Code


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

import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;

import java.util.List;

import java.util.stream.Collectors;

public class Main {
    public static List<String> getFileNames(List<String> fileNames, Path dir) {
        int foundFiles = 0;
        try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
            for (Path path : stream) {
                if (path.toFile().isDirectory()) {
                    getFileNames(fileNames, path);
                } else {
                    foundFiles++;/*from www.j av a2 s  . c om*/
                    fileNames.add(path.toAbsolutePath().toString());
                    if ((foundFiles % 100) == 0) {
                        System.out.print(".");
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return filterNotPoms(fileNames);
    }

    public static List<String> filterNotPoms(List<String> fileNames) {
        List<String> retRes = fileNames.stream().filter(path -> containPomXml(path)).collect(Collectors.toList());

        return retRes;
    }

    private static boolean containPomXml(String aString) {
        if (aString.endsWith("pom.xml")) {
            return true;
        } else {
            return false;
        }
    }
}

Related

  1. getFileName(String path)
  2. getFileName(String relativePath)
  3. getFileNameFromPath(String filePath)
  4. getFileNameFromPath(String str)
  5. getFilenameOrLastPath(String path)
  6. getFileNames(List fileNames, Path dir, String ext, boolean recursive)
  7. getFileNames(List fileNames, Path dir, String sFilter)
  8. getFileNameWithoutExt(final Path file)
  9. getFilePath(String dirName)