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
Actions | Description |
---|---|
Compare(Libraries.Language.Object object) | This action compares two object hash codes and returns an integer. |
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 an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.
Example Code
Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)
Parameters
- Libraries.Language.Object: The object to compare to.
Return
integer: 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
- Libraries.Language.Object: The to be compared.
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
- text path: the path to set
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
- text path: the path to set