我想使用AntBuilder的fileScanner遍历目录。
我的代码如下:
scanner = new AntBuilder().fileScanner {
fileset(dir:sourcedir, casesensitive:false) {
include(name:pattern)
type(type:'dir')
}
}
我想在目录上使用扫描仪循环,例如:
for (file in scanner) {
assert file.directory == true
}
有什么想法吗? 感谢!!!!!!!!
答案 0 :(得分:2)
以下是使用fileScanner
scanner = new AntBuilder().fileScanner {
fileset(dir:sourcedir, casesensitive:false) {
include(name:pattern)
}
}
// Just the directories
scanner.directories().each {
println it.name
}
您也可以使用Groovy调用来执行此操作:
def dirs = []
new File( sourcedir ).eachDirRecurse {
// Check the name here, obviously the Ant pattern you have probably won't work
if( it.name ==~ pattern ) dirs << it
}
dirs.each {
println it.name
}