6

在我的 gradle 任务中,我遍历 fileTree 并且一切正常:

myTask {
  fileTree("${project.projectDir}/dir").visit { FileVisitDetails details ->
    exec {
      //do some operations
    }
  }
}

但现在我的目录中有不同类型的文件:

dir
├── sub1
│   ├── file1.json
│   └── file2.js
├── sub2
│   ├── file1.json
│   └── file2.js
└── sub3
    ├── file1.js
    └── file2.json

如何仅迭代某些类型的文件?因为

"${project.projectDir}/folder/dir/**/*.json"

不工作。

感谢您的任何建议

4

1 回答 1

6

您应该使用matching来自 的方法FileTree。它使用PatternFilterableas 参数。

试试看:

fileTree("${project.projectDir}/dir").matching {
    include "**/*.json"
}.each {
    // do some operations
}
于 2018-11-07T13:51:29.133 回答