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
Not at a computer, but you could try
def count = new File("c:\\shared").listFiles()
.findAll { it.name ==~ /.*s/ }
.size()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With