List directory contents with AntBuilder
This shows how to list the content of a directory with AntBuilder.
def ant = new AntBuilder()
def list = ant.fileScanner {
fileset(dir:"stuff")
}
list.each() { file ->
println "sizeof ${file.getName()} is ${file.length()} bytes"
}
list = ant.fileScanner {
fileset(dir:"stuff") {
include(name:"*.txt")
exclude(name:"*.doc")
}
}
list.each { file ->
println "sizeof ${file.name} is ${file.length()} bytes"
}
The first fileScanner will print out.
sizeof 1.doc is 0 bytes sizeof 1.txt is 0 bytes sizeof 2.doc is 0 bytes sizeof 2.txt is 0 bytes sizeof 3.doc is 0 bytes sizeof 3.txt is 0 bytes sizeof 4.txt is 0 bytes sizeof 5.txt is 0 bytes sizeof 1.doc is 0 bytes sizeof 1.txt is 0 bytes sizeof 2.doc is 0 bytes sizeof 2.txt is 0 bytes sizeof 3.doc is 0 bytes sizeof 3.txt is 0 bytes sizeof 4.txt is 0 bytes sizeof 5.txt is 0 bytes
the second one.
sizeof 1.txt is 0 bytes sizeof 2.txt is 0 bytes sizeof 3.txt is 0 bytes sizeof 4.txt is 0 bytes sizeof 5.txt is 0 bytes
since it will exclude all files which end with *.doc.