file functions
Functions for working with files.
file.Exists
Reports whether a file or directory exists at the given path.
Added in gomplate v2.4.0
Usage
Arguments
| name | description |
|---|---|
path |
(required) The path |
Examples
input.tmpl:
file.IsDir
Reports whether a given path is a directory.
Added in gomplate v2.4.0
Usage
Arguments
| name | description |
|---|---|
path |
(required) The path |
Examples
input.tmpl:
file.Read
Reads a given file as text. Note that this will succeed if the given file is binary, but the output may be gibberish.
Added in gomplate v2.4.0
Usage
Arguments
| name | description |
|---|---|
path |
(required) The path |
Examples
file.ReadDir
Reads a directory and lists the files and directories contained within.
Added in gomplate v2.4.0
Usage
Arguments
| name | description |
|---|---|
path |
(required) The path |
Examples
file.Stat
Returns a os.FileInfo describing the named path.
Essentially a wrapper for Go’s os.Stat function.
Added in gomplate v2.4.0
Usage
Arguments
| name | description |
|---|---|
path |
(required) The path |
Examples
file.Walk
Like a recursive file.ReadDir, recursively walks the file tree rooted at path, and returns an array of all files and directories contained within.
The files are walked in lexical order, which makes the output deterministic but means that for very large directories can be inefficient.
Walk does not follow symbolic links.
Similar to Go’s filepath.Walk function.
Added in gomplate v2.6.0
Usage
Arguments
| name | description |
|---|---|
path |
(required) The path |
Examples
file.Write
Write the given data to the given file. If the file exists, it will be overwritten.
For increased security, file.Write will only write to files which are contained within the current working directory. Attempts to write elsewhere will fail with an error.
Non-existing directories in the output path will be created.
If the data is a byte array ([]byte), it will be written as-is. Otherwise, it will be converted to a string before being written.
Added in gomplate v2.4.0
Usage
Arguments
| name | description |
|---|---|
filename |
(required) The name of the file to write to |
data |
(required) The data to write |