# 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

```go
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:

```go
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:

```go
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:

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

Source: https://docs.platforma.bio/sdk-path-lib/
