See also

- Decorators for more decorators

# @files_re

## @files_re (tasks_or_file_names, matching_regex, [input_pattern], output_pattern, [extra_parameters,…])

### Legacy design now deprecated. We suggest using @transform() instead

> Purpose:

> > All singing, all dancing decorator which can do everything that @merge() and @transform() can do.

> > Applies the task function to transform data from input to output files.

> > Output file names are determined from tasks_or_file_names, i.e. from the output of specified tasks, or a list of file names, using regular expression pattern substitutions.

> > Only out of date tasks (comparing input and output files) will be run.

> Example:

>       from ruffus import *
>       #
>       #   convert all files ending in ".1" into files ending in ".2"
>       #
>       @files_re('*.1', '(.*).1', r'\1.2')
>       def transform_func(infile, outfile):
>           open(outfile, "w").write(open(infile).read() + "\nconverted\n")

>       pipeline_run([task_re])

> If the following files are present `a.1`, `b.1`, `c.1`, this will result in the following function calls:

>       transform_func("a.1", "a.2")
>       transform_func("b.1", "b.2")
>       transform_func("c.1", "c.2")

> Parameters:

> - tasks_or_file_names
>     can be a:
>     1. Task / list of tasks (as in the example above).
>          File names are taken from the output of the specified task(s)
>     2. (Nested) list of file name strings.
>          File names containing `*[]?` will be expanded as a glob .
>            E.g.:`"a.*" => "a.1", "a.2"`

> - matching_regex

>     a python regular expression string.

>     See python regular expression (re) documentation for details of regular expression syntax
>     Each output file name is created using regular expression substitution with output_pattern

> - input_pattern
>     Optionally specifies the resulting input file name(s).

> - output_pattern
>     Specifies the resulting output file name(s).

> - [extra_parameters, …]

>     Any extra parameters are passed to the task function.

>     Regular expression substitution is first applied to (even nested) string parameters.
>     Other data types are passed verbatim.
>     For example:

>           from ruffus import *
>           #
>           #   convert all files ending in ".1" into files ending in ".2"
>           #
>           @files_re('*.1', '(.*).1', r'\1.2', [r'\1', 55], 17)
>           def transform_func(infile, outfile, extras, extra3):
>               extra1, extra2 = extras
>               open(outfile, "w").write(open(infile).read() + "\nconverted%s\n" % (extra1, extra2, extra3))

>           pipeline_run([transform_func])

>     If the following files are present `a.1`, `b.1`, `c.1`, this will result in the following function calls:

>           transform_func("a.1", "a.2", ["a", 55], 17)
>           transform_func("b.1", "b.2", ["b", 55], 17)
>           transform_func("c.1", "c.2", ["c", 55], 17)