# Understanding relative paths

**URL:** <https://community.seqera.io/t/understanding-relative-paths/2165>\
**Category:** Ask for help\
**Tags:** nextflow\
**Created:** [May 27, 2025, 1:54pm UTC](https://community.seqera.io/t/understanding-relative-paths/2165 "2025-05-27T13:54:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fredfarrell123](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/fredfarrell123/32/1828_2.png) [@fredfarrell123](https://community.seqera.io/u/fredfarrell123)\
**Post date:** [May 27, 2025, 1:54pm UTC](https://community.seqera.io/t/understanding-relative-paths/2165/1 "2025-05-27T13:54:22Z")

</div>

Hi, I’m struggling to understand how specify relative file paths.

Take this minimal example:

```auto
process CAT_FILES {

    input:
    path file1
    path file2

    output:
    path "result.txt"

    script:
    """
    cat $file1 $file2 > result.txt
    """

}

workflow {

    CAT_FILES(params.first_file, params.second_file)

}

```

say I have foo.txt and bar.txt in a folder data in the current directory. I want to specify my params in the nextflow.config:

```auto
params {

    first_file = "./data/foo.txt"
    second_file = "./data/bar.txt"

}

```

and I get

ERROR ~ Error executing process \> ‘CAT\_FILES’

Caused by:  
Not a valid path value: ‘./data/foo.txt’

I’ve tried setting NXF\_FILE\_ROOT=$(pwd)/data and just putting the file names in the config, but that doesn’t work either.

Is there a way to do this?

---

<div class="post-metadata">

**Author:** ![mahesh.binzerpanchal](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/mahesh.binzerpanchal/32/253_2.png) [@mahesh.binzerpanchal](https://community.seqera.io/u/mahesh.binzerpanchal)\
**Post date:** [May 27, 2025, 2:06pm UTC](https://community.seqera.io/t/understanding-relative-paths/2165/2 "2025-05-27T14:06:50Z")

</div>

The issue here I think is that you’re trying to use a `String` object where it expects a `Path` object.

Strings are turned into `Path` objects using channel factories like `Channel.fromPath` and `Channel.fromFilePairs`. [Channel factories — Nextflow documentation](https://www.nextflow.io/docs/latest/reference/channel.html#channel-factory)

Another way is to use the `file` function from the Nextflow standard library.

> **[Namespaces — Nextflow documentation](https://www.nextflow.io/docs/latest/reference/stdlib-namespaces.html#global-namespace)**

```auto
workflow {
    CAT_FILES(
        Channel.value( file(params.first_file, checkIfExists: true) ), 
        Channel.value( file(params.second_file, checkIfExists: true) )
     )
}

```

Files must be passed as `Path` objects so Nextflow knows to symlink them in the task working directory ( known as staging ).

---

<div class="post-metadata">

**Author:** ![fredfarrell123](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/fredfarrell123/32/1828_2.png) [@fredfarrell123](https://community.seqera.io/u/fredfarrell123)\
**Post date:** [May 27, 2025, 3:41pm UTC](https://community.seqera.io/t/understanding-relative-paths/2165/3 "2025-05-27T15:41:26Z")

</div>

Ah thank you Mahesh, that seems to work! The checkIfExists is also useful. So I guess my issue was that I was providing file arguments that weren’t channels.

---

<div class="post-metadata">

**Author:** ![mahesh.binzerpanchal](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/mahesh.binzerpanchal/32/253_2.png) [@mahesh.binzerpanchal](https://community.seqera.io/u/mahesh.binzerpanchal)\
**Post date:** [May 28, 2025, 10:34am UTC](https://community.seqera.io/t/understanding-relative-paths/2165/4 "2025-05-28T10:34:53Z")

</div>

No, it was the types. You could also do

```auto
workflow {
    CAT_FILES(
        file(params.first_file, checkIfExists: true), 
        file(params.second_file, checkIfExists: true)
     )
}

```

but this exactly the same as above. Non channel objects are implicitly converted into value channels when passed to a process, or emitted from a workflow.

I used the former because it’s easier to understand.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/system/32/2402_2.png) [@system](https://community.seqera.io/u/system)\
**Post date:** [June 19, 2025, 7:10am UTC](https://community.seqera.io/t/understanding-relative-paths/2165/5 "2025-06-19T07:10:40Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
