December 1, 2014

Gradle script to list xml files recursively from specified directory

In the previous article, we saw how to list xml files recursively from the specified directory using Ant Script.

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 '-----------------------------------------'
}

No comments:

Post a Comment