@Test public void mustCountDirectoryContents() throws Exception { File dir = directory( "dir" ); File file = new File( dir, "file" ); File subdir = new File( dir, "subdir" ); file.createNewFile(); subdir.mkdirs(); assertThat( FileUtils.countFilesInDirectoryPath( dir.toPath() ), is( 2L ) ); }
private boolean directoryIsEmpty( Path dir ) throws IOException { return Files.notExists( dir ) || Files.isDirectory( dir ) && FileUtils.countFilesInDirectoryPath( dir ) == 0; }