1

我想使用 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
}

任何想法 ?谢谢!!!!!!!!

4

1 回答 1

2

Here's how to do it with fileScanner

scanner = new AntBuilder().fileScanner {
    fileset(dir:sourcedir, casesensitive:false) {
        include(name:pattern)
    }
}

// Just the directories
scanner.directories().each {
    println it.name
}

You could also do it with Groovy calls:

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
}
于 2013-06-20T08:27:21.807 回答