While Sprig does not grant access to the filesystem, it does provide functions for working with strings that follow file path conventions.
Paths separated by the slash character (/), processed by the path package.
Examples:
/home/user/file, /etc/config;https://example.com/some/content/, ftp://example.com/file/.Return the last element of a path.
base "foo/bar/baz"
The above prints "baz".
Return the directory, stripping the last part of the path. So dir "foo/bar/baz"
returns foo/bar.
Clean up a path.
clean "foo/bar/../baz"
The above resolves the .. and returns foo/baz.
Return the file extension.
ext "foo.bar"
The above returns .bar.
To check whether a path is absolute, use isAbs.
Paths separated by the os.PathSeparator variable, processed by the path/filepath package.
These are the recommended functions to use when parsing paths of local filesystems, usually when dealing with local files, directories, etc.
Examples:
/):
/home/user/file, /etc/config;\):
C:\Users\Username\, C:\Program Files\Application\;Return the last element of a filepath.
osBase "/foo/bar/baz"
osBase "C:\\foo\\bar\\baz"
The above prints "baz" on Linux and Windows, respectively.
Return the directory, stripping the last part of the path. So osDir "/foo/bar/baz"
returns /foo/bar on Linux, and osDir "C:\\foo\\bar\\baz"
returns C:\\foo\\bar on Windows.
Clean up a path.
osClean "/foo/bar/../baz"
osClean "C:\\foo\\bar\\..\\baz"
The above resolves the .. and returns foo/baz on Linux and C:\\foo\\baz on Windows.
Return the file extension.
osExt "/foo.bar"
osExt "C:\\foo.bar"
The above returns .bar on Linux and Windows, respectively.
To check whether a file path is absolute, use osIsAbs.