# Can publishDir in be dynamically set based on input type?

**URL:** <https://community.seqera.io/t/can-publishdir-in-be-dynamically-set-based-on-input-type/1081>\
**Category:** Ask for help\
**Created:** [August 12, 2024, 11:24am UTC](https://community.seqera.io/t/can-publishdir-in-be-dynamically-set-based-on-input-type/1081 "2024-08-12T11:24:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zaka-edd](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/zaka-edd/32/904_2.png) [@zaka-edd](https://community.seqera.io/u/zaka-edd)\
**Post date:** [August 12, 2024, 11:24am UTC](https://community.seqera.io/t/can-publishdir-in-be-dynamically-set-based-on-input-type/1081/1 "2024-08-12T11:24:36Z")

</div>

Hi,

I’m working on a Nextflow pipeline and I’m trying to figure out if it’s possible to dynamically set the `publishDir` for outputs based on the input type. Specifically, I have a process that I use twice for both case and control as a tuple of values and paths, and I want the output to be published to different directories depending on one of the values in the tuple.

Here’s a simplified version of the process I’m working with:

```auto
#!/usr/bin/env nextflow

process tupled_data {
    publishDir "/home/zeddafir/scripts/nextflow/test_next/case", mode: 'copy', overwrite: true
    publishDir "/home/zeddafir/scripts/nextflow/test_next/control", mode: 'copy', overwrite: true

    input:
    tuple val(sampleName), path(samplePath), val(sampleType)

    output:
    path(path("${sampleName}.txt"))

    script:
    """
    echo "${sampleName} content" > ${sampleName}.txt
    """
}

```

---

<div class="post-metadata">

**Author:** ![ChrisHakk](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/chrishakk/32/21_2.png) [@ChrisHakk](https://community.seqera.io/u/ChrisHakk)\
**Post date:** [August 13, 2024, 11:56am UTC](https://community.seqera.io/t/can-publishdir-in-be-dynamically-set-based-on-input-type/1081/2 "2024-08-13T11:56:31Z")

</div>

If `sampleType` is your `case` or `control` you could use try something like this:

```auto
#!/usr/bin/env nextflow

process tupled_data {
    publishDir "/home/zeddafir/scripts/nextflow/test_next/${sampleType}", mode: 'copy', overwrite: true

    input:
    tuple val(sampleName), path(samplePath), val(sampleType)

    output:
    path(path("${sampleName}.txt"))

    script:
    """
    echo "${sampleName} content" > ${sampleName}.txt
    """
}

```
