Introduction
GetFiles was first launched in February 2019. It retrieves a list of files from a specified folder.
Requirements
- Craft 3.1 or above
- You need a simple way of retrieving files which are not managed by Craft
Examples
List the contents of a directory
Inside /assets/images there are 3 image files:
In Twig we pass an array of settings into GetFiles. The settings array contains the path of the folder to list:
This would output:
List the contents of a directory which matches a regex pattern
Inside /assets/images there are 3 files:
In Twig we pass an array of settings into GetFiles. The settings array contains the path of the folder to list and a regex pattern to match:
This would output:
Configuration
path
string, required
A valid folder for GetFiles to search
pattern
string, optional, default value '*'
A regex pattern to match
pathformat
string, optional, default value '2'
- Filename only
- Filename relative to your base path (default value)
- Absolute path to the filename
Installation
If you have any issues, feedback or ideas, please feel free to submit an issue on Github.
Read this next