Here you can find the source of isDirectoryEmpty(Path directory)
Parameter | Description |
---|---|
directory | directory to check |
public static boolean isDirectoryEmpty(Path directory) throws IOException
//package com.java2s; /*/*from w w w . j ava 2 s. c o m*/ * This file is part of DiscoSync (home: github.com, leitwolf7/discosync) * * Copyright (C) 2015, 2015 leitwolf7 * * DiscoSync is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * DiscoSync is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with DiscoSync. If not, see <http://www.gnu.org/licenses/>. */ import java.io.IOException; import java.nio.file.*; public class Main { /** * Check if the directory is empty. * * @param directory directory to check * @return true when empty */ public static boolean isDirectoryEmpty(Path directory) throws IOException { boolean retval = true; DirectoryStream<Path> dirStream = Files.newDirectoryStream(directory); if (dirStream.iterator().hasNext()) { retval = false; } dirStream.close(); return retval; } }