所以我在目录中有很多档案,如下所示:
test_61995.zip test_61234.zip test_61233.zip
我只想使用Gradle从这里复制最新文件。 possilbe是对文件和日期和时间进行排序并复制usng gradle吗?
答案 0 :(得分:3)
当然可以。这是一个例子
科特琳DSL:
tasks {
val cp by creating(Copy::class.java) {
from(File("/home/madhead/Downloads/").listFiles().sortedBy { it.lastModified() }.last())
into(File("/home/madhead/Downloads/so53777253/"))
}
}
Groovy DSL:
task cp(type: Copy) {
from(new File("/home/madhead/Downloads/").listFiles().sort{ it.lastModified() }[0])
into(new File("/home/madhead/Downloads/so53777253/"))
}
这会将最新的修改文件从/home/madhead/Downloads/
复制到/home/madhead/Downloads/so53777253/
。