Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java nio, get all subfolders of some folder

Tags:

java

nio

How could I get all subfolders of some folder? I would use JDK 8 and nio.

picture

for example, for folder "Designs.ipj" method should return {"Workspace", "Library1"}

Thank you in advance!

like image 513
M. Black Avatar asked Jul 08 '16 14:07

M. Black


1 Answers

    List<Path> subfolder = Files.walk(folderPath, 1)
            .filter(Files::isDirectory)
            .collect(Collectors.toList());

it will contains folderPath and all subfolders in depth 1. If you need only subfolders, just add:

subfolders.remove(0);
like image 149
Wsl_F Avatar answered Oct 14 '22 17:10

Wsl_F