Link Search Menu Expand Document

Path

Table of contents

  1. Path
    1. Constants
    2. Path.basename(String) -> String
    3. Path.dirname(String) -> String
    4. Path.extname(String) -> String
    5. Path.isAbsolute(String) -> Boolean
    6. Path.realpath(String) -> Result<String>
    7. Path.exists(String) -> Boolean
    8. Path.isDir(String) -> Boolean
    9. Path.listDir(String) -> List
    10. Path.join(Iterable) -> String

Path

To make use of the Path module an import is required.

import Path;

Constants

Constant Description
Path.delimiter System dependent path delimiter
Path.dirSeparator System dependent directory separator

Path.basename(String) -> String

Returns the basename of the path.

Path.basename("/usr/bin"); // 'bin'

Path.dirname(String) -> String

Returns the directory name of the path.

Path.dirname("/usr/bin"); // '/usr'

Path.extname(String) -> String

Returns the extension portion of the path, including the dot.

Path.extname("/tmp/t.ext"); // '.ext'
Path.extname("/tmp/t");     // ''

Path.isAbsolute(String) -> Boolean

Returns true if path is absolute, false otherwise.

Path.isAbsolute("/usr"); // true
Path.isAbsolute("usr");  // false

Path.realpath(String) -> Result<String>

Returns A result type and unwraps the canonicalized absolute pathname as a string.

Note: This is not available on windows systems.

Path.realpath("/dir/../dir/../dir"); // '/dir'

Path.exists(String) -> Boolean

Returns a boolean whether a file exists at a given path.

Path.exists("some/path/to/a/file.du"); // true

Path.isDir(String) -> Boolean

Checks whether a given path points to a directory or not.

Note: This is not available on windows systems.

Path.isDir("/usr/bin/"); //true

Path.listDir(String) -> List

Returns a list of strings containing the contents of the input path.

Note: This function does not guarantee any ordering of the returned list.

Path.listDir("/"); // ["bin", "dev", "home", "lib", ...]

Path.join(Iterable) -> String

Returns the provided string arguments joined using the directory separator.

Note: A trailing directory separator is ignored from each argument

Path.join('/tmp', 'abcd', 'efg') == '/tmp/abcd/efg';
Path.join(['/tmp', 'abcd', 'efg']) == '/tmp/abcd/efg';
Path.join('/tmp/', 'abcd/', 'efg/') == '/tmp/abcd/efg';

This site uses Just The Docs, with modifications.