Groovy count number of files matches regex in the directory

Viewed 6434

I am using this code to count number of files ends with 's' in a directory.

            def count=0
        def p = ~/.*s/
        new File("c:\\shared").eachFileMatch(p) { file->
            println file.getName().split("\\.")[0]
            count++
        }
        print "$count"

If there way to avoid the temp variable and use some method in File class itself?

Thanks

1 Answers
Related