小编Joh*_*Doe的帖子

Groovy 从列表中删除特定文件

我尝试删除我可以在folderPath. 但我只想删除名称为“Jenkins”的那个。
如何在列表中定义仅删除该文件。?

示例:
在 C:\test\test 中有 3 个文件,要删除名称中包含 Jenkins 的文件:

文件

import groovy.io.FileType

String folderPath = "C:\\test" + "\\" + "test"
def list = []
def dir = new File("$folderPath")
dir.eachFileRecurse (FileType.FILES) { file ->
  list << file
}
list.each {
println it.findAll() == "Jenkins" // Just files witch include in list "Jenkins" name
}
Run Code Online (Sandbox Code Playgroud)

感谢您的提示!

groovy file

3
推荐指数
1
解决办法
9398
查看次数

标签 统计

file ×1

groovy ×1