Skip to content
FutureBlitz

    Install

    Import std.io.path

    std.io.path

    std.io's paths: a Path is where a file or folder is, as text, read by Windows' rules or POSIX's, the target's unless it's made with the other's. A String converts to one wherever a Path is expected. Its own separator is '/' on every OS, which it writes wherever it joins or rebuilds a path, and Windows takes it, so a program's paths read the same everywhere; on Windows '' is one too, and a path can start with a drive, like "C:", or a server's share, like "//server/share". What a Path does to its text is only text: nothing here looks at the disk but Absolute, which asks for the current folder.

    std/io/path.fb

    Types

    PathStyle enum

    Public Enum PathStyle

    Whose rules a Path reads its text by.

    std/io/path.fb, line 18

    • POSIX enum member #

      Linux's and macOS's: / between names.

    • WINDOWS enum member #

      Windows's: \ or / between names, and a drive, like C:, or a share, like //server/share, before them.

    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.

    std/io/path.fb, line 35

    • 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.

      Doc from std.core.interfaces.Comparable.Operator<.

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

      Whether a and b are equal.

      Doc from std.core.interfaces.Equatable.Operator==.

    • Public Method Hash(): UInt64 method #

      Its hash, the same for values that are equal.

      Doc from std.core.interfaces.Hashable.Hash.

    • Public Method ToString(): String method #

      Its text, as a string interpolation like "{value}" shows it.

      Doc from std.core.interfaces.Printable.ToString.

    • 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 "games/save.dat" and for "games/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: "games" for "games/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:/games", 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 "games" to "games/saves/one.dat", and "../music" from "games" 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.