I have the following folder structure under build folder (which you get during a Gradle build):
CDROM/disk1 CDROM/disk1/disk1file1a.txt CDROM/disk1/disk1file1b.txt CDROM/disk2/disk2file2a.txt CDROM/disk2/disk2file2btxt CDROM/disk2/disk2folder2x CDROM/disk2/disk2folder2y CDROM/disk3 CDROM/disk3/disk3 CDROM/disk3/disk33 CDROM/disk3/disk33/disk3 CDROM/folder1 CDROM/file1.txt
How can I tell Gradle to show me the following:
Print only the top level / direct child folders (only) in folder "CDROM"
i.e. it should print only disk1, disk2, disk3 and folder1
Print only the top level / direct child folders (only) which has a pattern of disk[0-9] i.e. diskX where X is a number.
i.e. it should print only disk1, disk2 and disk3
The following will do it, but I think there should be an efficient way to achieve the same and where one can define patterns and DON'T have to use "IF" statements that I have used below.
FileTree dirs = fileTree (dir: "$buildDir/CDROM", include: "disk*/**")
dirs.visit { FileVisitDetails fd ->
if (fd.directory && fd.name.startsWith('disk')){
println "------ $buildDir/CDROM_Installers/${fd.name} ---------------"
}
}
By top level if you mean only direct children of CDROM
then this should be as easy as:
new File("${buildDir}/CDROM").eachDir{ if(it.name ==~/disk.*/) println it}
If you want more control on depth and other things, then you can try variations of following code:
new File("${buildDir}/CDROM").traverse( [maxDepth: 2, filter: ~/.*disk\d/,
type: groovy.io.FileType.DIRECTORIES]){
println it // or do whatever
}
see traverse for more details.
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