@ Nonnegative public static int count ( @ Nonnull final Path dir ) throws IOException { try ( final DirectoryStream < Path > stream = Files . newDirectoryStream ( dir ) ) { return Iterables . size ( stream ) ; } catch ( DirectoryIteratorException ex ) { // I/O error encounted during the iteration, the cause is an IOException throw ex . getCause ( ) ; } }
Count the number of entries in a directory .