Finding Directories That Contain Specific Files

After accomplishing my task in Groovy, I was wondering if I was missing the Gradle way of doing it. What I want to do is get a list of directories that contain two specific files. This is how I did it in Groovy:

def specialDirectory = []
new File('.').eachFileRecurse(DIRECTORIES) { directory ->
    def found = []
    directory.eachFileMatch(ANY, ~/^fileNameOne.txt$|^fileNameTwo.txt$/) {
        found << it
    if( found.size > 1) {
        specialDirectory << directory

Is there a “better” way to do it with Gradle?

Hey Kevin,
I think that is fine. The only problem might be new File('.') which can cause issues in different build environments. you might want to replace it with project.file(".") which always returns the project related file path.


1 Like

Thanks for the feedback!