Search code examples
nextflow

Get file list from directory channel nexflow


Is there a way to specify the folder name and then create a channel with the file names inside it in nextflow?

And yes I could make a file with the contents of the directory, that's not what i'm asking.

Thanks


Solution

  • I think you can just use the fromPath factory method for this. If you want all files in the directory and in all sub-directories, you can use the double asterisk to cross directory boundaries:

    params.search_dir = './directory'
    
    
    workflow {
    
        Channel
            .fromPath( "${params.search_dir}/**" )
            .view()
    }
    

    Otherwise, a single asterisk will match only files in the top-level directory. Append hidden: true if you also need your output to include hidden files. Note that multiple paths or glob patterns can also be specified using a list, for example:

    params.search_dir = './directory'
    params.another_dir = './another/directory'
    
    
    workflow {
    
        Channel
            .fromPath( [ "${params.search_dir}/**", "${params.another_dir}/*" ) ]
            .view()
    }