pypyr.steps.pathcheck permalink

check if paths exist permalink

Check if a path exists on the filesystem. Supports globbing. A path can point to a file or a directory.

input permalink

The pathCheck context key must exist.

- name: pypyr.steps.pathcheck
    pathCheck: ./do/i/exist.arb # single literal path
- name: pypyr.steps.pathcheck
    pathCheck: ./**/*.py # single glob expression

If you want to check for the existence of multiple paths, you can pass a list instead. You can freely mix literal paths and globs.

- name: pypyr.steps.pathcheck
      - ./file1 # literal relative path
      - ./dirname # also finds dirs
      - ./**/{arbkey}* # glob with a string formatting expression

All inputs support string substitutions. This means you can specify another context item to be an individual path, or part of a path, or the entire path list.

output permalink

After pathcheck completes, the pathCheckOut context key is available. This contains the results of the pathcheck operation.

    # the key is the ORIGINAL input, no string formatting applied.
    'inpath-is-the-key': # one of these for each pathCheck input
        exists: true # bool. True if path exists.
        count: 0 # int. Number of files found for in path.
        found: ['path1', 'path2'] # list of strings. Paths of files found.

Example of passing a single input and the expected output context:

pathCheck: ./myfile # assuming ./myfile exists in $PWD
    exists: true,
    count: 1,
      - './myfile'

The exists and count keys can be very useful for conditional decorators to help decide whether to run subsequent steps. You can use these directly in string formatting expressions without any extra fuss.

- name: pypyr.steps.pathcheck
    pathCheck: ./**/*.arb
- name: pypyr.steps.echo
  run: '{pathCheckOut[./**/*.arb][exists]}'
    echoMe: you'll only see me if ./**/*.arb found something on filesystem.

See a worked example for pathcheck.

see also

last updated on .