Libraries.System.Path Documentation

The Path class is used to represent a path on the system. A path can be either absolute or relative. This class provides a consistent interface for manipulating paths, and provides a system that is more or less consistent throughout operating systems.

Example Code

// TODO

Inherits from: Libraries.Language.Object

Summary

Actions Summary Table

ActionsDescription
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns a CompareResult.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
GetHashCode()This action gets the hash code for an object.
GetPath()Get the set path.
IsPathAbsolute()Returns true if the set path is absolute.
IsPathRelative()Returns true if the set path is relative.
SetAbsolutePath(text path)Set an absolute path.
SetRelativePath(text path)Set a relative path.

Actions Documentation

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns a CompareResult. The compare result is either larger if this hash code is larger than the object passed as a parameter, smaller, or equal.

Example Code

use Libraries.Language.Support.CompareResult
        Object o
        Object t
        CompareResult result = o:Compare(t)

Parameters

Return

Libraries.Language.Support.CompareResult: The Compare result, Smaller, Equal, or Larger.

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Example Code

use Libraries.Language.Object
        use Libraries.Language.Types.Text
        Object o
        Text t
        boolean result = o:Equals(t)

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

GetHashCode()

This action gets the hash code for an object.

Example Code

Object o
        integer hash = o:GetHashCode()

Return

integer: The integer hash code of the object.

GetPath()

Get the set path. This may be either relative or absolute; to find out, use the IsPathRelative() and IsPathAbsolute() actions. If no path is set, an InvalidPathError is thrown.

Example Code

use Libraries.System.Path

        Path p
        p:SetRelativePath("./hello.txt")
        output p:GetPath() // willoutput  "./hello.txt"

        p:SetAbsolutePath("/Users/jeff")
        output p:GetPath() // willoutput  "/Users/jeff"

        p:SetAbsolutePath("C:\Windows\")
        output p:GetPath() // willoutput  "C:\Windows\"

Return

text: the absolute or relative path set for this instance of Path.

IsPathAbsolute()

Returns true if the set path is absolute. This action will raise an InvalidPathError if this instance of "Path" does not have a set path using either the SetPathAbsolute() or SetPathRelative() action. An "absolute" path is a path that refers to an exact location on disk--that is, what the path refers to is independent of the current directory. As an example, /hello.txt is an absolute path, as on UNIX systems, it refers to a file under the root of the hard disk, outside of any particular directory. In addition, the path C:\Program Files is also absolute, as it refers to the "Program Files" directory on the "C" drive in Windows. If we were to write the path Program Files this would refer to the "Program Files" in the current directory, which could be on any drive, not necessarily just "C." If a path is not absolute, it is relative. For a description of relative paths, see the IsPathRelative() action in this class.

Example Code

use Libraries.System.Path

        Path p
        p:SetAbsolutePath("C:\Windows")
        output p:IsPathAbsolute() // willoutput  "true", as we called SetAbsolutePath

        p:SetAbsolutePath("/Users/jeff") // on Mac and Unix/Linux systems, '/' means root of file system.
        output p:IsPathAbsolute() // willoutput  "true", as we called SetAsolutePath

Return

boolean: true if the path is absolute; false otherwise.

IsPathRelative()

Returns true if the set path is relative. A "relative" path is a path that does not refer to an exact location--that is, what it refers to depends on the current directory our application is in. As an example, the path ./hello.txt is relative, as is foo.txt as these both refer to files in the current directory. In addition, the path images/bar.png is also relative, as it refers to a file in the "images" directory under the current directory. If a path is not relative, it is absolute. For a description of absolute paths, see the IsPathAbsolute() action in this class.

Example Code

use Libraries.System.Path

        Path p
        p:SetRelativePath("./hello.txt")
        output p:IsPathRelative() // willoutput  "true", as we called SetRelativePath

Return

boolean: true if the path is relative; false otherwise.

SetAbsolutePath(text path)

Set an absolute path. See IsAbsolutePath() for an explanation of absolute paths. If the given path is not absolute, an InvalidPathError will be raised.

Example Code

use Libraries.System.Path

        Path p
        p:SetAbsolutePath("C:\Windows")
        p:SetAbsolutePath("/Users/jeff") // on Mac and Unix/Linux systems, '/' means root of file system.

Parameters

SetRelativePath(text path)

Set a relative path. See IsRelativePath() for an explanation of relative paths. If the given path is not relative, an InvalidPathError will be raised.

Example Code

use Libraries.System.Path

        Path p
        p:SetRelativePath("./hello.txt") // in current directory
        p:SetRelativePath("../../hello.txt") // go 2 directories up from our current directory
        p:SetRelativePath("hello.txt") // in current directory

Parameters