Get list of files > Documentation  > Workflow Actions  > Get list of files

Get list of files

Creates a list of files that matched given filename pattern or false if nothing matched.

Get list of files – automate WordPress

Get list of files – automate WordPress

You have to specify a pattern starting with either relative path based on the root of the WordPress installation or absolute path on the web server. Absolute path begins with slash /.

Every element in the resulting list will contain either filename with absolute path or a nested list with keys: name, date, time, size. In the first case, to get name of the first file in the list you have to use pattern: {PREVIOUS[0]}, for the second file: {PREVIOUS[1]}. In the second case you will get two-level list, so for name of the first file use pattern with numerical key: {PREVIOUS[0][name]}, for size: {PREVIOUS[0][size]}, for time: {PREVIOUS[0][time]}, for date: {PREVIOUS[0][date]}. Date and time will be formatted according WordPress settings you have set in General Settings > Date Format, Time Format.

In a real workflow you don not need to use all those patterns with keys because you can easily format resulting list with Format list action that will create a nice bulleted or numbered HTML list.

Special symbols in a pattern

  1. Star * represents one or more any characters in a filename (wildcard)
  2. Question mark ? represents exactly one character
  3. A set of variants can be specified within two braces {} with comma. For instance, to retrieve a list of all uploaded images (if you have default Media settings for your WordPress): wp-content/uploads/*/*/*.{png,jpg,gif}

Another examples with relative path and variable DATE.

  • Retrieve a list of all images uploaded this year: wp-content/uploads/{DATE[Y]}/*/*.{png,jpg,gif}
  • Retrieve a list of all PDF files uploaded this month: wp-content/uploads/{DATE[Y]}/{DATE[m]}/*.pdf

Tips: To display a list of files on the web page you can use Format list action, to read the content of a file use File get contents, to iterate over the list of files use Iterate next action.

Note: This action does not perform recursive search through a directory tree. For safety reasons, PHP and JS files are excluded from the resulting list.

No Comments

Sorry, the comment form is closed at this time.