Edit this page on GitHub

Home > docs > plugins v2 > Files Task

Files Task

The files task provides methods to handle local files within the working directory of a Concord workflow process.

Usage

To be able to use the task in a Concord flow, it must be added as a dependency:

configuration:
  dependencies:
  - mvn://com.walmartlabs.concord.plugins.basic:file-tasks:1.103.0

This adds the task to the classpath and allows you to invoke it in any flow.

Methods

Check File Existence

The exists(path) method returns true when a given path exists within the working directory.

- if: "${files.exists('myFile.txt')}"
  then:
    - log: "found myFile.txt"

The notExists(path) method returns true when a given path does not exist within the working directory.

- if: "${files.notExists('myFile.txt')}"
  then:
    - throw: "Cannot continue without myFile.txt!"

Move a File

The move(src, dstDir) method moves a file to a different directory. The returned value is the new path.

- set:
    myFile: "${files.move('myFile.txt', 'another/dir)}"

# prints: "another/dir/myFile.txt"
- log: "${myFile}"

Construct a Relative Path

The relativize(pathA, pathB) method returns a relative path from the first path to the second path.

- set:
    relativePath: "${files.relativize('subDirA/myscript', 'subDirB/opts.cfg')}"

- log: "${relativePath}"
# prints: '../../subDirB/opts.cfg'