File
Methods for working with the filesystem, via file and dir TypeStrings.
$lines = file'files:data.txt'.read() $files = dir'files:images'.readDir()
Error HandlingMost file operations will throw an exception if they fail. If you want to recover from a non-essential file operation, wrap it in a
try/catch.TemplatesFile operations are not callable within templates, in order to keep your View code separate from your app logic.
Paths
You can prefix a path with a root key to define the base directory path.
| Root Key | Description |
|---|---|
| app: | Your app’s root directory |
| files: | Same as app:data/files |
| public: | The webserver document root (Default: app:/code/public) |
| home: | User account’s home directory (equivalent to ~) |
file'files:/dictionary.txt' //= Ex: '/path/to/yourApp/data/files/dictionary.txt' dir'files:/public:/images' //= Ex: '/path/to/yourApp/code/public/images'
Paths Defined in Configuration
Within .jcon files, keys that are suffixed with Dir or File will automatically be cast to that kind of TypeString.
// file: config/app.jcon
app: {
logDir: /path/to/logs
dataFile: /path/to/data.txt
}
// ... in your code ...
AppConfig.get('logDir')
//= dir'/path/to/logs'
AppConfig.get('dataFile')
//= file'/path/to/data.txt'