Last active
December 6, 2022 08:12
-
-
Save kdabir/7181617 to your computer and use it in GitHub Desktop.
A groovy directory traverse that excludes given dirs. Change the last closure to do something interesting instead of printing the dir name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.io.FileType | |
import groovy.io.FileVisitResult | |
final excludedDirs = ['.svn', '.git', '.hg', '.idea', 'node_modules', '.gradle', 'build'] | |
int count = 0 | |
new File(root).traverse( | |
type : FileType.DIRECTORIES, | |
preDir : { if (it.name in excludedDirs) return FileVisitResult.SKIP_SUBTREE }, // excludes children of excluded dirs | |
excludeNameFilter : { it in excludedDirs }, // excludes the excluded dirs as well | |
// nameFilter : { it == 'settings.gradle'} // matched only given names | |
) {println it; count++} | |
println "count:$count" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment