gpt4 book ai didi

Gradle 打印文件夹中的目录 - X 级别

转载 作者:行者123 更新时间:2023-12-03 02:45:08 26 4
gpt4 key购买 nike

我在构建文件夹下有以下文件夹结构(您在 Gradle 构建期间获得):

CDROM/disk1CDROM/disk1/disk1file1a.txtCDROM/disk1/disk1file1b.txtCDROM/disk2/disk2file2a.txtCDROM/disk2/disk2file2btxtCDROM/disk2/disk2folder2xCDROM/disk2/disk2folder2yCDROM/disk3CDROM/disk3/disk3CDROM/disk3/disk33CDROM/disk3/disk33/disk3CDROM/folder1CDROM/file1.txt

How can I tell Gradle to show me the following:

  1. Print only the top level / direct child folders (only) in folder "CDROM"
    i.e. it should print only disk1, disk2, disk3 and folder1

  2. 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} ---------------"

}

}

最佳答案

如果您指的是CDROM的直接子级,那么顶层应该很简单:

new File("${buildDir}/CDROM").eachDir{ if(it.name ==~/disk.*/) println it}

如果您想更多地控制深度和其他东西,那么您可以尝试以下代码的变体:

new File("${buildDir}/CDROM").traverse( [maxDepth: 2, filter: ~/.*disk\d/, 
type: groovy.io.FileType.DIRECTORIES]){
println it // or do whatever
}

参见traverse了解更多详情。

关于Gradle 打印文件夹中的目录 - X 级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24917972/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com