【发布时间】:2014-10-27 10:55:40
【问题描述】:
我有一个列出目录中所有 pdf 文件的工作脚本。它按预期工作,但我实际上需要的只是第一个 pdf 文件的文件名。然后我想打破eachFileMatch(),因为目录中可能有数千个pdf文件。
我尝试在eachFileMatch().find 之后从这个Break from groovy each closure 答案中使用find,但没有工作Caught: groovy.lang.MissingMethodException: No signature of method: java.io.File.eachFileMatch() is applicable for argument types: (java.util.regex.Pattern) values: [.*.(?i)pdf]
def directory="c:\\tmp" // place 2 or more pdf files in that
// directory and run the script
def p = ~/.*.(?i)pdf/
new File( directory ).eachFileMatch(p) { pdf ->
println pdf // and break
}
谁能告诉我怎么做?
【问题讨论】: