Skip to main content

Path Library

Introduction

A library that provides working with paths as strings on any platform: Windows, Linux and MacOS.

Sources

https://github.com/milaboratory/platforma/blob/main/sdk/workflow-tengo/src/path.lib.tengo

API

Import

path := import("@platforma-sdk/workflow-tengo:path")

join

Joins path elements into a single path.

Arguments:

  • elems: ...string - any number of elements.

Return:

  • result: string - a joined path.

Example:

joinedPath := path.join("dir1", "dir2", "nested dir with spaces", "file.txt")

split

Splits a path to path components.
If it was a file name, the last component will be this name.

Arguments:

  • path: string - the path
  • sep: string - an optional path separator.

Return:

  • components: []string - all directories and a file name at the end.

Example:

ll.assert(
path.split("dir1/dir2/dir3/abc.txt") ==
path.split("dir1/dir2/dir3/abc.txt", "/") ==
["dir1", "dir2", "dir3", "abc.txt"]
)

regexpJoin

Like join, joins elements to a single path, but can be used safely in regexps.

Arguments:

  • elems: ...string - any number of elements.

separator

Returns a path separator. "/" on Unix-like systems, "\" on Windows.

Example:

if path.separator[0] == '/' {
// run Unix and MacOS specific code
} else {
// run Windows specific code
}