API Reference

Class List

pc.path

File path API

Summary

Static Properties

delimiterThe character that separates path segments

Static Methods

extractPathReturn the path without file name.
getBasenameReturn the basename of the path.
getDirectoryGet the directory name from the path.
getExtensionReturn the extension of the path.
isRelativePathCheck if a string s is relative path.
joinJoin two sections of file path together, insert a delimiter if needed.
normalizeNormalize the path by removing '.
splitSplit the pathname path into a pair [head, tail] where tail is the final part of the path after the last delimiter and head is everything leading up to that.

Details

Static Properties

delimiterThe character that separates path segments

Static Methods

extractPath(s)

Return the path without file name. if path is relative path, start with period.

pc.path.extractPath("path/to/file.txt"); // returns "./path/to"

Parameters

sStringThe full path to process.

Returns

String The path without a last element from list split by slash.

getBasename(path)

Return the basename of the path. That is the second element of the pair returned by passing path into pc.path.split.

pc.path.getBasename("/path/to/file.txt"); // returns "path.txt"
pc.path.getBasename("/path/to/dir"); // returns "dir"

Parameters

pathStringThe path to process.

Returns

String The basename.

getDirectory(path)

Get the directory name from the path. This is everything up to the final instance of pc.path.delimiter.

Parameters

pathStringThe path to get the directory from

Returns

String The directory part of the path.

getExtension(path)

Return the extension of the path. Pop the last value of a list after path is split by question mark and comma.

pc.path.getExtension("/path/to/file.txt"); // returns ".txt"
pc.path.getExtension("/path/to/file.jpg"); // returns ".jpg"
pc.path.getExtension("/path/to/file.txt?function=getExtension"); // returns ".txt"

Parameters

pathStringThe path to process.

Returns

String The extension.

isRelativePath(s)

Check if a string s is relative path.

pc.path.isRelativePath("file.txt"); // returns true
pc.path.isRelativePath("path/to/file.txt"); // returns true
pc.path.isRelativePath("./path/to/file.txt"); // returns true
pc.path.isRelativePath("../path/to/file.jpg"); // returns true
pc.path.isRelativePath("/path/to/file.jpg"); // returns false
pc.path.isRelativePath("http://path/to/file.jpg"); // returns false

Parameters

sStringThe path to process.

Returns

Boolean True if s doesn't start with slash and doesn't include colon and double slash.

join(one, two)

Join two sections of file path together, insert a delimiter if needed.

Parameters

oneStringFirst part of path to join.
twoStringSecond part of path to join.

Returns

String The joined file path.

normalize(path)

Normalize the path by removing '.' and '..' instances

Parameters

pathStringThe path to normalize

Returns

String The normalized path

split(path)

Split the pathname path into a pair [head, tail] where tail is the final part of the path after the last delimiter and head is everything leading up to that. tail will never contain a slash

Parameters

pathStringThe path to split.

Returns

String[] The split path which is an array of two strings, the path and the filename.