Here you can find the source of getDirectoryNames(Path baseDirectory)
public static Set<String> getDirectoryNames(Path baseDirectory)
//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; } }