Here is the code snippet to do the same in Gradle script.
import groovy.io.FileType
// defining defaulttasks
defaultTasks 'listfile'
task listfile ()<< {
// user defined property - srcdir
ext.srcdir = "D:\Src"
println ' '
}
listfile.doFirst {
print '-----------------------------------------'
}
listfile << {
def list = []
def dir = new File(listfile.srcdir)
dir.eachFileRecurse (FileType.FILES) { file ->
if(file.name.endsWith('.xml')) {
list << file
}
}
println 'List of xml files: \n-----------------------------------------'
list.each {
println it.path
}
println '-----------------------------------------'
}