Skip to content
FutureBlitz

    Install

    Import std.io.path

    Path

    std.io.path

    struct

    Public Struct Path Implements Comparable, Hashable, Printable

    Where a file or folder is. Paths are equal when their texts and styles are, so "a/b" and "a//b" aren't until Normalize makes them so, and they sort by their styles, POSIX's first, then by their texts' bytes. A Path's zero, as a Struct's Field starts with, is "" by the target's rules, as Path("") is.

    Examples

    Local save = Path("app/one/save.dat", PathStyle.POSIX)
    Expect(save.FileName() == "save.dat")
    Expect(save.Stem() == "save" && save.Extension() == ".dat")
    Expect(save.Parent() == Path("app/one", PathStyle.POSIX))
    Expect(save.WithExtension(".bak").Text == "app/one/save.bak")
    Expect(Path("a/./b/../c", PathStyle.POSIX).Normalize().Text == "a/c")
    Expect(Path("C:\\app", PathStyle.WINDOWS).IsAbsolute())

    std/io/path.fb, line 49

    • Public ReadOnly Field Text: String field #

      Its text, as it was given.

    • Public New(text: String) constructor #

      A path by the target's rules.

    • Public New(text: String, style: PathStyle) constructor #

      A path by style's rules, whatever the target's are.

    • Public Property Style: PathStyle property #

      Whose rules it reads its text by.

    • Public Static Method NativeStyle(): PathStyle static method #

      The target's style: WINDOWS on Windows, and POSIX everywhere else.

    • Operator /(a: Path, b: Path): Path operator #

      b after a, as Join puts it: saves / "one.dat", since a String converts to a Path.

    • Operator <(a: Path, b: Path): Bool operator #

      Whether a comes before b: by their styles, and then by their texts' bytes.

    • Operator ==(a: Path, b: Path): Bool operator #

      Whether the two have the same text and style, which paths to one place written two ways don't: Normalize them first.

    • Public Method Hash(): UInt64 method #

      A hash of its text and style, which Paths that are equal share.

    • Public Method ToString(): String method #

      Its text, as it was given.

    • Public Method Join(other: Path): Path method #

      other after this one, with a '/' between them unless this one ends with a separator. An other that's absolute is where it says, and on Windows one that starts at a root, like "/saves", is on this one's drive. An empty one adds nothing, and this one empty gives it.

    • Public Method FileName(): String method #

      The last name in the path, "" when it has none, as a root doesn't: "save.dat" for "app/save.dat" and for "app/save.dat/" too.

    • Public Method Stem(): String method #

      The file name without its extension: "save" for "save.dat", ".config" for ".config", and "archive.tar" for "archive.tar.gz".

    • Public Method Extension(): String method #

      The file name's extension with its dot, like ".dat", or "" when it has none. A name that starts with its only dot, like ".config", or ends with one has none.

    • @PanicsAtCaller Public Method WithExtension(extension: String): Path method #

      The path with its file name's extension extension, which a dot is put before when it has none, or without one when it's "": "save.bak" for "save.dat" and ".bak". The name is FileName's, so "a/b/." and "a/b/" give "a/b.bak", without what follows the name. Panics when the path has no file name to give one, as a root or ".." doesn't, or for an extension with a separator in it, or that ends with a dot, which a name can't end its extension with.

    • Public Method Parent(): Path method #

      The folder the path's in: "app" for "app/save.dat", "." for "save.dat", and the root for a root, worked out from its text alone, so the parent of ".." is ".". It has '/' between its names.

    • Public Method IsAbsolute(): Bool method #

      Whether the path says where it is without the current folder: one from a POSIX root, and on Windows one from a drive's root, like "C:/app", or a share, like "//server/share".

    • Public Method Normalize(): Path method #

      The same place in the fewest names: '/' between them, no "." or empty ones, and each ".." taking out the name before it, which is only text, so a link's ".." isn't followed. One with no names left is "." or its root. On Windows, a drive or share keeps its case, and a share is written without a separator after it, which "//server/share/" has.

    • Public Method RelativeTo(base: Path): Path? method #

      The path from base to this one, by their texts, with ".." for each of base's names they don't share: "saves/one.dat" from "app" to "app/saves/one.dat", and "../music" from "app" to "music". On Windows, names that differ only in their ASCII letters' case are the same. Null when one is absolute and the other isn't, they're on different drives, or base goes up past where this one starts, as "../other" from "a" does.

    • @PanicsAtCaller Public Method Absolute(): Path Throws IOError method #

      The path from the current folder's root, normalized: the path itself when it's absolute. On Windows, one from a root without a drive is on the current folder's drive. Throws an IOError when the OS doesn't say what the current folder is. Panics for a path by the other OS's rules that isn't absolute by them, since the current folder is by the target's.

    Report an issue with this page or with FutureBlitz on GitHub.