All File-path functions
Name | Function header | Example | Result | Description | Errorhandling |
---|---|---|---|---|---|
base | func(path string) string | [[ $result := toString (base "/usr/shared/Documents/test.md" ) ]] |
$result = “test.md” | The base function return the last element of the path. |
|
clean | func(path string) string | [[ $result := toString (clean "/usr/shared/Documents/test.md" ) ]] |
$result = “test.md” | The clean function returns the shortest path name equivalent to path by purely lexical processing. It applies the following rules iteratively until no further processing can be done: |
|
dir | func(path string) string | [[ $result := toString (dir "/usr/shared/Documents/test.md" ) ]] |
$result = “/usr/shared/Documents” | The dir function returns all but the last element of path, typically the path’s directory. |
|
ext | func(path string) string | [[ $result := toString (ext "/usr/shared/Documents/test.md" ) ]] |
$result = “.md” | The ext function returns the file name extension used by path. |
|
isAbs | func(path string) bool | [[ $result := toString (isAbs "/usr/shared/Documents/test.md" ) ]] |
$result = “true” | The isAbs function reports whether the path is absolute. If the path is relative, it contains false. |
func(path string) string
The base
function return the last element of the path.
If the last element is a file, it will present the filename.
Application notes / Limits:
//TODO - Windows: you got the whole path including file-name.
Examples
_comment Windows Examples
[[ $result := toString (base "C:\\testpath\\CamelCase\\test.docx" ) ]]
$result = "C:\\testpath\\CamelCase\\test.docx"
[[ $result := toString (base "C:\\testpath\\CamelCase" ) ]]
$result = "C:\\testpath\\CamelCase"
_commment Linux Examples
[[ $result := toString (base "/usr/shared/Documents/test.md" ) ]]
$result = "test.md"
[[ $result := toString (base "/usr/shared/Documents" ) ]]
$result = "Documents"
_commment Linux Examples with slashes and dots
[[ $result := toString (base "./../../../../" ) ]]
$result = ".."
[[ $result := toString (base "////" ) ]]
$result = "/"
[[ $result := toString (base "././../test/.." ) ]]
$result = ".."
func(path string) string
The clean
function returns the shortest path name equivalent to path by purely lexical processing. It applies the following rules iteratively until no further processing can be done:
Application notes / Limits:
The returned path ends in a slash only if it is the root “/”. If the result of this process is an empty string, Clean returns the string “.”. See also Rob Pike, ``Lexical File Names in Plan 9 or Getting Dot-Dot Right,”
Examples
_comment Windows Examples
[[ $result := toString (clean "C:\\testpath\\CamelCase\\test.docx" ) ]]
$result = "C:\\testpath\\CamelCase\\test.docx"
[[ $result := toString (clean "C:\\testpath\\CamelCase" ) ]]
$result = "C:\\testpath\\CamelCase"
_commment Linux Examples
[[ $result := toString (clean "/usr/shared/Documents/test.md" ) ]]
$result = "test.md"
[[ $result := toString (clean "/usr/shared/Documents" ) ]]
$result = "Documents"
_commment Linux Examples with slashes and dots
[[ $result := toString (clean "./../../../../" ) ]]
$result = ".."
[[ $result := toString (clean "////" ) ]]
$result = "/"
[[ $result := toString (clean "./../../test/../max/Muster" ) ]]
$result = "../../max/Muster"
func(path string) string
The dir
function returns all but the last element of path, typically the path’s directory.
Application notes / Limits:
After dropping the final element using Split, the path is Cleaned and trailing slashes are removed.
If the path is empty, Dir returns “.”. If the path consists entirely of slashes followed by non-slash bytes, Dir returns a single slash. In any other case, the returned path does not end in a slash.
Application notes / Limits:
Examples
_comment Windows Examples
[[ $result := toString (dir "C:\\testpath\\CamelCase\\test.docx" ) ]]
$result = "C:\\testpath\\CamelCase\\test.docx"
[[ $result := toString (dir "C:\\testpath\\CamelCase" ) ]]
$result = "C:\\testpath\\CamelCase"
_commment Linux Examples
[[ $result := toString (dir "/usr/shared/Documents/test.md" ) ]]
$result = "/usr/shared/Documents"
[[ $result := toString (dir "/usr/shared/Documents" ) ]]
$result = "Documents"
_commment Linux Examples with slashes and dots
[[ $result := toString (dir "./../../../../" ) ]]
$result = ".."
[[ $result := toString (dir "////" ) ]]
$result = "/"
[[ $result := toString (dir "./../../test/../max/Muster" ) ]]
$result = "../../max/Muster"
func(path string) string
The ext
function returns the file name extension used by path. If the path is relative, it contains false.
The extension is the suffix beginning at the final dot in the final slash-separated element of path; it is empty if there is no dot.
Examples
_comment Windows Examples
[[ $result := toString (ext "C:\\testpath\\CamelCase\\test.docx" ) ]]
$result = ".docx"
[[ $result := toString (ext "C:\\testpath\\CamelCase" ) ]]
$result = ""
_commment Linux Examples
[[ $result := toString (ext "/usr/shared/Documents/test.md" ) ]]
$result = ".md"
[[ $result := toString (ext "/usr/shared/Documents" ) ]]
$result = ""
_commment Linux Examples with slashes and dots
[[ $result := toString (ext "./../../../../" ) ]]
$result = ""
[[ $result := toString (ext "/////" ) ]]
$result = ""
[[ $result := toString (ext "./../../test/../max/Muster" ) ]]
$result = ""
func(path string) bool
The isAbs
function reports whether the path is absolute.
Examples
_comment Windows Examples
[[ $result := toString (isAbs "C:\\testpath\\CamelCase\\test.docx" ) ]]
$result = "false"
[[ $result := toString (isAbs "C:\\testpath\\CamelCase" ) ]]
$result = "false"
_commment Linux Examples
[[ $result := toString (isAbs "/usr/shared/Documents/test.md" ) ]]
$result = "true"
[[ $result := toString (isAbs "/usr/shared/Documents" ) ]]
$result = "true"
_commment Linux Examples with slashes and dots
[[ $result := toString (isAbs "./../../../../" ) ]]
$result = "false"
[[ $result := toString (isAbs "/////" ) ]]
$result = "true"
[[ $result := toString (isAbs "./../../test/../max/Muster" ) ]]
$result = "false"