Gradle - how to iterate in fileTree only for certain type of file
up vote
2
down vote
favorite
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
gradle filetree
add a comment |
up vote
2
down vote
favorite
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
gradle filetree
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
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
gradle filetree
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
gradle filetree
gradle filetree
edited Nov 7 at 13:55
ToYonos
10.9k22445
10.9k22445
asked Nov 7 at 13:41
Adrian Wąt
568
568
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
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
}
1
With some changes:fileTree("${project.projectDir}/dir/").matching { include "**/*.json" }.visit { FileVisitDetails details -> exec { //do some operations }
it works! :) Thanks for help
– Adrian Wąt
Nov 7 at 14:16
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
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
}
1
With some changes:fileTree("${project.projectDir}/dir/").matching { include "**/*.json" }.visit { FileVisitDetails details -> exec { //do some operations }
it works! :) Thanks for help
– Adrian Wąt
Nov 7 at 14:16
add a comment |
up vote
2
down vote
accepted
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
}
1
With some changes:fileTree("${project.projectDir}/dir/").matching { include "**/*.json" }.visit { FileVisitDetails details -> exec { //do some operations }
it works! :) Thanks for help
– Adrian Wąt
Nov 7 at 14:16
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
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
}
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
}
answered Nov 7 at 13:51
ToYonos
10.9k22445
10.9k22445
1
With some changes:fileTree("${project.projectDir}/dir/").matching { include "**/*.json" }.visit { FileVisitDetails details -> exec { //do some operations }
it works! :) Thanks for help
– Adrian Wąt
Nov 7 at 14:16
add a comment |
1
With some changes:fileTree("${project.projectDir}/dir/").matching { include "**/*.json" }.visit { FileVisitDetails details -> exec { //do some operations }
it works! :) Thanks for help
– Adrian Wąt
Nov 7 at 14:16
1
1
With some changes:
fileTree("${project.projectDir}/dir/").matching { include "**/*.json" }.visit { FileVisitDetails details -> exec { //do some operations }
it works! :) Thanks for help– Adrian Wąt
Nov 7 at 14:16
With some changes:
fileTree("${project.projectDir}/dir/").matching { include "**/*.json" }.visit { FileVisitDetails details -> exec { //do some operations }
it works! :) Thanks for help– Adrian Wąt
Nov 7 at 14:16
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53190618%2fgradle-how-to-iterate-in-filetree-only-for-certain-type-of-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown