/** * Processes each descendant file in this directory and any sub-directories. * Processing consists of calling <code>closure</code> passing it the current * file (which may be a normal file or subdirectory) and then if a subdirectory was encountered, * recursively processing the subdirectory. * * @param self a Path (that happens to be a folder/directory) * @param closure a Closure * @throws java.io.FileNotFoundException if the given directory does not exist * @throws IllegalArgumentException if the provided Path object does not represent a directory * @see #eachFileRecurse(Path, groovy.io.FileType, groovy.lang.Closure) * @since 2.3.0 */ public static void eachFileRecurse(Path self, @ClosureParams(value = SimpleType.class, options = "java.nio.file.Path") Closure closure) throws IOException { // throws FileNotFoundException, IllegalArgumentException { eachFileRecurse(self, FileType.ANY, closure); }
/** * Recursively processes each descendant subdirectory in this directory. * Processing consists of calling <code>closure</code> passing it the current * subdirectory and then recursively processing that subdirectory. * Regular files are ignored during traversal. * * @param self a Path (that happens to be a folder/directory) * @param closure a closure * @throws java.io.FileNotFoundException if the given directory does not exist * @throws IllegalArgumentException if the provided Path object does not represent a directory * @see #eachFileRecurse(Path, groovy.io.FileType, groovy.lang.Closure) * @since 2.3.0 */ public static void eachDirRecurse(final Path self, @ClosureParams(value = SimpleType.class, options = "java.nio.file.Path") final Closure closure) throws IOException { //throws FileNotFoundException, IllegalArgumentException { eachFileRecurse(self, FileType.DIRECTORIES, closure); }
/** * Processes each descendant file in this directory and any sub-directories. * Processing consists of potentially calling <code>closure</code> passing it the current * file (which may be a normal file or subdirectory) and then if a subdirectory was encountered, * recursively processing the subdirectory. Whether the closure is called is determined by whether * the file was a normal file or subdirectory and the value of fileType. * * @param self a Path (that happens to be a folder/directory) * @param fileType if normal files or directories or both should be processed * @param closure the closure to invoke on each file * @throws java.io.FileNotFoundException if the given directory does not exist * @throws IllegalArgumentException if the provided Path object does not represent a directory * @since 2.3.0 */ public static void eachFileRecurse(final Path self, final FileType fileType, @ClosureParams(value = SimpleType.class, options = "java.nio.file.Path") final Closure closure) throws IOException { // throws FileNotFoundException, IllegalArgumentException { // throws FileNotFoundException, IllegalArgumentException { checkDir(self); try (DirectoryStream<Path> stream = Files.newDirectoryStream(self)) { for (Path path : stream) { if (Files.isDirectory(path)) { if (fileType != FileType.FILES) closure.call(path); eachFileRecurse(path, fileType, closure); } else if (fileType != FileType.DIRECTORIES) { closure.call(path); } } } }