filepath functions
gomplate’s path functions are split into 2 namespaces:
path, which is useful for manipulating slash-based (/) paths, such as in URLsfilepath, which should be used for local filesystem paths, especially when Windows paths may be involved.
This page documents the filepath namespace - see also the path documentation.
These functions are wrappers for Go’s path/filepath package.
filepath.Base
Returns the last element of path. Trailing path separators are removed before extracting the last element. If the path is empty, Base returns .. If the path consists entirely of separators, Base returns a single separator.
A wrapper for Go’s filepath.Base function.
Added in gomplate v2.7.0
Usage
Arguments
| name | description |
|---|---|
path |
(required) The input path |
Examples
filepath.Clean
Clean returns the shortest path name equivalent to path by purely lexical processing.
A wrapper for Go’s filepath.Clean function.
Added in gomplate v2.7.0
Usage
Arguments
| name | description |
|---|---|
path |
(required) The input path |
Examples
filepath.Dir
Returns all but the last element of path, typically the path’s directory.
A wrapper for Go’s filepath.Dir function.
Added in gomplate v2.7.0
Usage
Arguments
| name | description |
|---|---|
path |
(required) The input path |
Examples
filepath.Ext
Returns the file name extension used by path.
A wrapper for Go’s filepath.Ext function.
Added in gomplate v2.7.0
Usage
Arguments
| name | description |
|---|---|
path |
(required) The input path |
Examples
filepath.FromSlash
Returns the result of replacing each slash (/) character in the path with the platform’s separator character.
A wrapper for Go’s filepath.FromSlash function.
Added in gomplate v2.7.0
Usage
Arguments
| name | description |
|---|---|
path |
(required) The input path |
Examples
filepath.IsAbs
Reports whether the path is absolute.
A wrapper for Go’s filepath.IsAbs function.
Added in gomplate v2.7.0
Usage
Arguments
| name | description |
|---|---|
path |
(required) The input path |
Examples
filepath.Join
Joins any number of path elements into a single path, adding a separator if necessary.
A wrapper for Go’s filepath.Join function.
Added in gomplate v2.7.0
Usage
Arguments
| name | description |
|---|---|
elem... |
(required) The path elements to join (0 or more) |
Examples
filepath.Match
Reports whether name matches the shell file name pattern.
A wrapper for Go’s filepath.Match function.
Added in gomplate v2.7.0
Usage
Arguments
| name | description |
|---|---|
pattern |
(required) The pattern to match on |
path |
(required) The path to match |
Examples
filepath.Rel
Returns a relative path that is lexically equivalent to targetpath when joined to basepath with an intervening separator.
A wrapper for Go’s filepath.Rel function.
Added in gomplate v2.7.0
Usage
Arguments
| name | description |
|---|---|
basepath |
(required) The base path |
targetpath |
(required) The target path |
Examples
filepath.Split
Splits path immediately following the final path separator, separating it into a directory and file name component.
The function returns an array with two values, the first being the directory, and the second the file.
A wrapper for Go’s filepath.Split function.
Added in gomplate v2.7.0
Usage
Arguments
| name | description |
|---|---|
path |
(required) The input path |
Examples
filepath.ToSlash
Returns the result of replacing each separator character in path with a slash (/) character.
A wrapper for Go’s filepath.ToSlash function.
Added in gomplate v2.7.0
Usage
Arguments
| name | description |
|---|---|
path |
(required) The input path |
Examples
filepath.VolumeName
Returns the leading volume name. Given C:\foo\bar it returns C: on Windows. Given a UNC like \\host\share\foo it returns \\host\share. On other platforms it returns an empty string.
A wrapper for Go’s filepath.VolumeName function.
Added in gomplate v2.7.0
Usage
Arguments
| name | description |
|---|---|
path |
(required) The input path |