Reputation: 502
in my gradle task I iterate through fileTree and all works good:
myTask {
fileTree("${project.projectDir}/dir").visit { FileVisitDetails details ->
exec {
//do some operations
}
}
}
but now I have different types of files in my directory:
dir
├── sub1
│ ├── file1.json
│ └── file2.js
├── sub2
│ ├── file1.json
│ └── file2.js
└── sub3
├── file1.js
└── file2.json
How to iterate for only certain type of files? Because
"${project.projectDir}/folder/dir/**/*.json"
doesnt work.
Thanks for any advice
Upvotes: 7
Views: 12072
Reputation: 16833
You should use the matching
method from FileTree
. It uses a PatternFilterable
as parameter.
Try that :
fileTree("${project.projectDir}/dir").matching {
include "**/*.json"
}.each {
// do some operations
}
Upvotes: 9