Recursive listing of all files matching a certain filetype in Groovy

I am trying to recursively list all files that match a particular file type in Groovy. This example almost does it. However, it does not list the files in the root folder. Is there a way to modify this to list files in the root folder? Or, is there a different way to do it?


This should solve your problem:

import static

new File('.').eachFileRecurse(FILES) {
    if('.groovy')) {
        println it

eachFileRecurse takes an enum FileType that specifies that you are only interested in files. The rest of the problem is easily solved by filtering on the name of the file. Might be worth mentioning that eachFileRecurse normally recurses over both files and folders while eachDirRecurse only finds folders.

groovy version 2.4.7 :

new File(pathToFolder).traverse(type: { it ->
    println it

you can also add filter like

new File(parentPath).traverse(type:, nameFilter: ~/patternRegex/) { it ->
    println it

replace eachDirRecurse by eachFileRecurseand it should work.

// Define closure
def result

findTxtFileClos = {

        it.eachFileMatch(~/.*.txt/) {file ->
                result += "${file.absolutePath}\n"

// Apply closure
findTxtFileClos(new File("."))

println result

Need Your Help

Searching by related fields in django admin

python django relational-database

I've been looking at the docs for search_fields in django admin in the attempt to allow searching of related fields.

Emmet - Notepad++ "Unknown exception"

python notepad++ emmet

Every time I'm trying to use Emmet's Expand Abbreviation it gives me errors. First a pop up with Unknown Exception and then another pop up with python script plugin did not accept the script.