Java Path File Name nio getDirectoryNames(Path baseDirectory)

Here you can find the source of getDirectoryNames(Path baseDirectory)

Description

get Directory Names

License

Open Source License

Declaration

public static Set<String> getDirectoryNames(Path baseDirectory) 

Method Source Code

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

import java.io.IOException;

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

import java.util.LinkedHashSet;
import java.util.Set;

public class Main {
    public static Set<String> getDirectoryNames(Path baseDirectory) {
        LinkedHashSet<String> result = new LinkedHashSet<>();
        try {//from  w ww .j  a v  a  2  s  .  com
            for (Path p : Files.newDirectoryStream(baseDirectory)) {
                if (Files.isDirectory(p)) {
                    String name = p.getFileName().toString();
                    if (!result.add(name)) {
                        throw new RuntimeException("duplicate directory: " + name);
                    }
                }
            }
        } catch (IOException e) {
            throw new RuntimeException("Error while reading directories", e);
        }
        return result;
    }
}

Related

  1. getContentPath(Path zipFilePath, String contentFileName)
  2. getDatabaseDirectoryPath(String databaseDirectory, String name)
  3. getDataPath(String filename)
  4. getDeckNameFromFile(final Path deckFile)
  5. getDefaultPathName(final String address, final long lspId)
  6. getFileContent(String fileNameOrPath)
  7. getFileInFolder(Path p, String filename)
  8. getFilename (final String filepath)
  9. getFilename(final Path path)