# Path¶

Represents a path. Contains suffixes that can be helpful when using and manipulating paths. You can use path() to create new instances.

Instances of this structure can be passed as arguments instead of ordinary, string paths, for example:

copypath("../file", path()).

structure Path
Suffix Type Description
VOLUME Volume Volume this path belongs to
SEGMENTS List of String List of this path’s segments
LENGTH Scalar Number of segments in this path
NAME String Name of file or directory this path points to
HASEXTENSION Boolean True if path contains an extension
EXTENSION String This path’s extension
ROOT Path Root path of this path’s volume
PARENT Path Parent path
CHANGENAME(name) Path Returns a new path with its name (last segment) changed
CHANGEEXTENSION(extension) Path Returns a new path with extension changed
ISPARENT(path) Boolean True if path is the parent of this path
COMBINE(name1, [name2, ...]) Path Returns a new path created by adding further elements to this one
Path:VOLUME
Type: Volume Get only

Volume this path belongs to.

Path:SEGMENTS
Type: List of String Get only

List of segments this path contains. Segments are parts of the path separated by /. For example path 0:/directory/subdirectory/script.ks contains the following segments: directory, subdirectory and script.ks.

Path:LENGTH
Type: Scalar Get only

Number of this path’s segments.

Path:NAME
Type: String Get only

Name of file or directory this path points to (same as the last segment).

Path:HASEXTENSION
Type: Boolean Get only

True if the last segment of this path has an extension.

Path:EXTENSION
Type: String Get only

Extension of the last segment of this path.

Path:ROOT
Type: Path Get only

Returns a new path that points to the root directory of this path’s volume.

Path:PARENT
Type: Path Get only

Returns a new path that points to this path’s parent. This method will throw an exception if this path does not have a parent (its length is 0).

Path:CHANGENAME(name)
Parameters: name – String new path name Path

Will return a new path with the value of the last segment of this path replaced (or added if there’s none).

Path:CHANGEEXTENSION(extension)
Parameters: extension – String new path extension Path

Will return a new path with the extension of the last segment of this path replaced (or added if there’s none).

Path:ISPARENT(path)
Parameters: path – Path path to check Boolean

Returns true if path is the parent of this path.

Path:COMBINE(name1, [name2, ...])
Parameters: name – String segments to add Path

Returns a new path that represents the file or directory that would be reached by starting from this path and then appending the path elements given in the list.

e.g:

set p to path("0:/home").
set p2 to p:combine("d1", "d2", "file.ks").
print p2
0:/home/d1/d2/file.ks