2010/05/06

Closure under Groovy


// using closure under groovy
// to display all contains in directory
def getFiles = { dir, rtn ->
dir.listFiles().each { file ->
if (file.isDirectory()) {
getFiles(file, rtn)
} else {
rtn.call(file) // action
}
}
}


getFiles(new File('/Users/tcchou/Desktop/ewtek'), { file ->
println file.getAbsolutePath()
})