本文介绍了用ant builder文件扫描器扫描groovy中的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的代码如下所示:



<$ p
$ b $(包括(名称:模式)
类型(类型:
fileset(dir:sourcedir,casesensitive:false){$ b $ scanner = new AntBuilder :'dir')
}
}

我想循环扫描仪只在目录上,例如:

$ p $ for(文件在扫描仪中){
assert file.directory == true
}

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

解决方案

以下是如何使用 fileScanner

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

//只需目录
scanner.directories()。 {
println it.name
}

您也可以使用Groovy调用:

  def dirs = [] 
新文件(sourcedir).eachDirRecurse {
// Check这里的名字,很明显,如果(it.name ==〜pattern)dirs<<<< it
}

dirs.each {
println it.name
}


I want to use fileScanner of AntBuilder to go over directories.

My code looks like:

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

I want to loop with the scanner just on directories, for example:

for (file in scanner) {
    assert file.directory == true
}

Any idea ?Thanks!!!!!!!!

解决方案

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
}

这篇关于用ant builder文件扫描器扫描groovy中的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 09:21