# Flexible publishDir in Nextflow Using the Same Process

**URL:** <https://community.seqera.io/t/flexible-publishdir-in-nextflow-using-the-same-process/2686>\
**Category:** Tips & Tricks\
**Tags:** nextflow\
**Created:** [May 24, 2026, 12:32pm UTC](https://community.seqera.io/t/flexible-publishdir-in-nextflow-using-the-same-process/2686 "2026-05-24T12:32:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Firas\_Zemzem](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/firas_zemzem/32/892_2.png) [@Firas\_Zemzem](https://community.seqera.io/u/Firas_Zemzem)\
**Post date:** [May 24, 2026, 12:32pm UTC](https://community.seqera.io/t/flexible-publishdir-in-nextflow-using-the-same-process/2686/1 "2026-05-24T12:32:34Z")

</div>

One thing I like in Nextflow is how “publishDir” can be made dynamic, avoiding duplicated processes.

> In my “FASTQC” workflow, I wanted the same process to handle both raw and trimmed reads while publishing outputs to different folders.

Instead of creating separate logic, I used a conditional `publishDir`

> publishDir(
> 
> path: { task.process.contains(‘TRIMMED\_FASTQC’)
> 
> ? “${params.outdir}/shortReads/checkQuality/trimmed/”
> 
> : “${params.outdir}/shortReads/checkQuality/raw/”
> 
> }, mode: ‘copy’
> 
> )

The trick is that I reused the same module with `include` and assigned it a new process name.

> include { FASTQC as TRIMMED\_FASTQC } from ‘./modules/fastqc’

Since “task.process” reflects the aliased process name, the same “FASTQC” module automatically publishes results to the correct location..

A small Nextflow trick that keeps pipelines easier to maintain. 😎
