Link Search Menu Expand Document

Path

Table of contents

  1. Path
    1. Constants
    2. Path.basename(string)
    3. Path.dirname(string)
    4. Path.extname(string)
    5. Path.isAbsolute(string)
    6. Path.realpath(string)
    7. Path.exists(string)
    8. Path.isDir(string)
    9. Path.listDir(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)

Returns the basename of the path.

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

Path.dirname(string)

Returns the directory name of the path.

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

Path.extname(string)

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

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

Path.isAbsolute(string)

Returns true if path is absolute, false otherwise.

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

Path.realpath(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)

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

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

Path.isDir(string)

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)

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", ...]

This site uses Just The Docs, with modifications.