Path
class in package klyn.io

    public class Path:

Path

Filesystem path API.

This class replaces the old `File` metadata API and exposes path manipulation, normalization and path-kind queries in a portable way.

    import klyn.io

    project = Path.cwd
    print(project)
    print(project.name)
    print(project.isDirectory)

    rawPath = Path("unexisting-path")
    print(type(rawPath))          # Path
    print(rawPath.exists)         # false

    existing = Path.get("README.txt")
    print(type(existing))         # FilePath or FolderPath

@since 1.0

Properties

Modifier and Type | Member | Description
--- | --- | ---
public static native readonly property | cwd `cwd as FolderPath` | Current working directory.
public native readonly property | exists `exists as Boolean` | Returns `true` if the path exists.
public native readonly property | extension `extension as String` | Returns the file extension without the leading dot, or `""`.
public native readonly property | isAbsolute `isAbsolute as Boolean` | Returns `true` if the path string is absolute.
public native readonly property | isDirectory `isDirectory as Boolean` | Returns `true` if the path exists and is a directory.
public readonly property | isFile `isFile as Boolean:` | Alias for `isRegular`.
public native readonly property | isNormalized `isNormalized as Boolean` | Returns `true` if the path string is already normalized.
public native readonly property | isRegular `isRegular as Boolean` | Returns `true` if the path exists and is a regular file.
public native readonly property | isSymlink `isSymlink as Boolean` | Returns `true` if the path is a symbolic link.
public static readonly property | klynHome `klynHome as FolderPath:` | Root directory of the Klyn installation/runtime.
public native readonly property | lastModified `lastModified as Long` | Returns the last modification timestamp in milliseconds since Unix epoch.
public native readonly property | name `name as String` | Returns the final path segment.
public native readonly property | size `size as ULong` | Returns the file size in bytes.
public static readonly property | tempDir `tempDir as FolderPath:` | OS temporary directory.
public static readonly property | userHome `userHome as FolderPath:` | Home directory of the current user.

Constructors

Modifier and Type | Member | Description
--- | --- | ---
public | Path `Path(filename as String):` | Creates a raw path object from a path string, even if the path does not exist.

Methods

Modifier and Type | Member | Description
--- | --- | ---
public | absolute `absolute() as Path:` | Compatibility alias of `toAbsolute()`.
public | delete `delete() as Void throws IOException:` | Compatibility alias of `remove()`.
public | endsWith `endsWith(suffix as String) as Boolean:` | Returns `true` if this path ends with the given path string suffix.
public static | file `file(base as Path, names... as String) as FilePath:` | Builds a file path from a base path and multiple segments.
public static | folder `folder(base as Path, names... as String) as FolderPath:` | Builds a folder path from a base path and multiple segments.
public static | get `get(filename as String) as Path:` | Resolves an existing filesystem path and returns a typed path instance.
public native | normalize `normalize() as Path` | Returns a normalized path.
public native | parent `parent() as Path` | Returns the parent path if available.
public | read `read() as String throws IOException:` | Reads the whole text content of this path.
public native | relativize `relativize(base as Path) as Path` | Returns a path relative to the given base path.
public native | remove `remove() throws IOException` | Removes the file or empty folder.
public native | rename `rename(newName as String) throws IOException` | Renames the path.
public native | resolve `resolve(other as String) as Path` | Resolves a child path against this path.
public | resolve `resolve(names... as String) as Path:` | Resolves multiple child segments against this path.
public | resolve `resolve(other as Path) as Path:` | Resolves another path against this path.
public static | resolve `resolve(base as Path, names... as String) as Path:` | Resolves multiple path segments against a base path.
public | startsWith `startsWith(base as Object) as Boolean:` | Returns `true` if this path starts with the given prefix (`Path` or `String`).
public native | toAbsolute `toAbsolute() as Path` | Returns an absolute version of the path.
public override | toString `toString() as String:` | Returns the raw path string.
public native | touch `touch() as Void throws IOException` | Creates a file when missing or updates its modification date.
public | write `write(content as String) as Void throws IOException:` | Writes text content to this path, replacing existing file content.

Operators

Modifier and Type | Member | Description
--- | --- | ---
public static | operator!=(left as Path, right as Path) as Boolean: | Negated path equality.
public static | operator==(left as Path, right as Path) as Boolean: | Compares two paths by normalized absolute textual representation.