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
A FileTree represents a hierarchy of files. It extends FileCollection to add hierarchy query and manipulation methods. You typically use a FileTree to represent files to copy or the contents of an archive. You can obtain a FileTree instance using Project.
Class ProcessResourcesCopies resources from their source to their target directory, potentially processing them. Makes sure no stale resources remain in the target directory.
> gradle -q test Adding test task to project ':project-a' Running tests for project ':project-a' This example uses method Project. afterEvaluate() to add a closure which is executed after the project is evaluated. It is also possible to receive notifications when any project is evaluated.
The doLast creates a task action that runs when the task executes. Without it, you're running the code at configuration time on every build.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With