Filesystem

The Filesystem registry allows for efficient interaction with the file system, providing functions to read, write, and manipulate files directly from your templates.

circle-info

You can easily import all the functions from the filesystem registry by including the following import statement in your code

import "github.com/go-sprout/sprout/registry/filesystem"

pathBase

The function returns the last element of a given path, effectively extracting the file or directory name from the full path.

Signature

Must version

❌

{{ "/path/to/file.txt" | pathBase }} // Output: "file.txt"

pathDir

The function returns all but the last element of a given path, effectively extracting the directory portion of the path.

Signature

Must version

❌

{{ "/" | pathDir }} // Output: "/"
{{ "/path/to/file.txt" | pathDir }} // Output: "/path/to"

pathExt

The function returns the file extension of the given path, identifying the type of file by its suffix.

Signature

Must version

❌

pathClean

The function cleans up a given path by simplifying any redundancies, such as removing unnecessary double slashes or resolving "." and ".." elements, resulting in a standardized and more straightforward path.

Signature

Must version

❌

pathIsAbs

The function checks whether the given path is an absolute path, returning true if it is and false if it is not.

Signature

Must version

❌

osBase

The function returns the last element of a given path, using the operating system's specific path separator to determine the path structure.

Signature

Must version

❌

osDir

The function returns all but the last element of a given path, using the operating system's specific path separator to navigate the directory structure.

Signature

Must version

❌

osExt

The function returns the file extension of a given path, using the operating system's specific path separator to accurately determine the extension.

Signature

Must version

❌

osClean

The function cleans up a given path, using the operating system's specific path separator to simplify redundancies and standardize the path structure.

Signature

Must version

❌

osIsAbs

The function checks whether the given path is absolute, using the operating system's specific path separator to determine if the path is absolute or relative.

Signature

Must version

❌

Last updated