Skip to content
Discussion options

You must be logged in to vote

You could create the folder from within your closure. I added new File("output/${meta.id}").mkdirs() to your code below and it works.

map_ch = Channel.of(
        ["id":"S1", "val":10],
        ["id":"S1", "val":20],
        ["id":"S2", "val":30],
        ["id":"S2", "val":40])

map_ch.collectFile(storeDir: "output", newLine: true) { meta ->
        new File("output/${meta.id}").mkdirs()
        def filename = "${meta.id}/${meta.id}.txt"
        return [filename, meta.val.toString()]
    }

Folder structure:

tree output/
output/
├── S1
│   └── S1.txt
└── S2
    └── S2.txt

3 directories, 2 files

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mribeirodantas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #4409 on October 31, 2023 02:40.