Here you can find the source of listChildren(Path dir, boolean searchDirectory)
Parameter | Description |
---|---|
dir | folder to search. |
searchDirectory | if true method return list of folders, otherwise list of files. |
Parameter | Description |
---|---|
IOException | when IO Exception occurs. |
public static List<Path> listChildren(Path dir, boolean searchDirectory) throws IOException
//package com.java2s; /*/*from w w w . j a va2 s.c o m*/ * CKFinder * ======== * http://cksource.com/ckfinder * Copyright (C) 2007-2015, CKSource - Frederico Knabben. All rights reserved. * * The software, this file and its contents are subject to the CKFinder * License. Please read the license.txt file before using, installing, copying, * modifying or distribute this file or part of its contents. The contents of * this file is part of the Source Code of CKFinder. */ 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; import java.util.stream.StreamSupport; public class Main { /** * Gets list of children folder or files for dir, according to searchDirectory * param. * * @param dir folder to search. * @param searchDirectory if true method return list of folders, otherwise * list of files. * @return list of files or subdirectories in selected directory * @throws IOException when IO Exception occurs. */ public static List<Path> listChildren(Path dir, boolean searchDirectory) throws IOException { DirectoryStream.Filter<Path> filter = searchDirectory ? Files::isDirectory : Files::isRegularFile; try (DirectoryStream<Path> ds = Files.newDirectoryStream(dir, filter)) { return StreamSupport.stream(ds.spliterator(), false).collect(Collectors.toList()); } } }