Ste*_*eve 5 unix scripting groovy ksh groovy-console
我正在努力将KornShell(ksh)脚本转换为Groovy.我有以下Find命令 - 什么是Groovy方法做类似的事情,而不依赖于Unix命令(我需要这个跨平台工作,所以我不能做"blah blah".execute()).
find <source directory> -name <file pattern> -type f -mtime +140 -level 0
Run Code Online (Sandbox Code Playgroud)
此代码搜索源文件目录中的所有文件(无子目录),这些文件与文件模式匹配且超过140天.
Groovy提供了一些搜索目录的方法:File.eachFile对于-level 0案例或File.eachFileRecurse一般情况.例:
use(groovy.time.TimeCategory) {
new File(".").eachFile { file ->
if (file.isFile() &&
file.lastModified() < (new Date() - 140.days).time) {
println file
}
}
}
Run Code Online (Sandbox Code Playgroud)