path

Module

Implements Path and related functions.

Aliases:

  • ​DIR_SEPARATOR = cond(apply(:!lit.signature<("self": !kgen.declref<@"$builtin"::@"$bool"::@Bool, !lit.metatype<@"$builtin"::@"$bool"::@Bool>> borrow) -> i1> @"$builtin"::@"$bool"::@Bool::@"__mlir_i1__($builtin::$bool::Bool)", apply(:!lit.signature<() -> !kgen.declref<@"$builtin"::@"$bool"::@Bool, !lit.metatype<@"$builtin"::@"$bool"::@Bool>>> @"$sys"::@"$info"::@"os_is_windows()")), #lit.struct<{value: string = "\\"}>, #lit.struct<{value: string = "/"}>)

Path

The Path object.

Fields:

  • ​path (String): The underlying path string representation.

Functions:

__init__

__init__(inout self: Self)

Initializes a path with the current directory.

__init__(inout self: Self, path: StringLiteral)

Initializes a path with the provided path.

Args:

  • ​path (StringLiteral): The file system path.

__init__(inout self: Self, path: StringRef)

Initializes a path with the provided path.

Args:

  • ​path (StringRef): The file system path.

__init__(inout self: Self, path: String)

Initializes a path with the provided path.

Args:

  • ​path (String): The file system path.

__copyinit__

__copyinit__(inout self: Self, existing: Self)

Copy constructor for the path struct.

Args:

  • ​existing (Self): The existing struct to copy from.

__eq__

__eq__(self: Self, other: Self) -> Bool

Returns True if the two paths are equal.

Args:

  • ​other (Self): The other path to compare against.

Returns:

True if the paths are equal and False otherwise.

__ne__

__ne__(self: Self, other: Self) -> Bool

Returns True if the two paths are not equal.

Args:

  • ​other (Self): The other path to compare against.

Returns:

True if the paths are not equal and False otherwise.

__truediv__

__truediv__(self: Self, suffix: Self) -> Self

Joins two paths using the system-defined path separator.

Args:

  • ​suffix (Self): The suffix to append to the path.

Returns:

A new path with the suffix appended to the current path.

__truediv__(self: Self, suffix: StringLiteral) -> Self

Joins two paths using the system-defined path separator.

Args:

  • ​suffix (StringLiteral): The suffix to append to the path.

Returns:

A new path with the suffix appended to the current path.

__truediv__(self: Self, suffix: StringRef) -> Self

Joins two paths using the system-defined path separator.

Args:

  • ​suffix (StringRef): The suffix to append to the path.

Returns:

A new path with the suffix appended to the current path.

__truediv__(self: Self, suffix: String) -> Self

Joins two paths using the system-defined path separator.

Args:

  • ​suffix (String): The suffix to append to the path.

Returns:

A new path with the suffix appended to the current path.

__str__

__str__(self: Self) -> String

Returns a string representation of the path.

Returns:

A string represntation of the path.

__repr__

__repr__(self: Self) -> String

Returns a printable representation of the path.

Returns:

A printable represntation of the path.

exists

exists(self: Self) -> Bool

Returns True if the path exists and False otherwise.

Returns:

True if the path exists on disk and False otherwise.

read_text

read_text(self: Self) -> String

Returns content of the file.

Returns:

Contents of file as string.

read_bytes

read_bytes(self: Self) -> Tensor[si8]

Returns content of the file as bytes.

Returns:

Contents of file as 1D Tensor of bytes.

suffix

suffix(self: Self) -> String

The path’s extension, if any. This includes the leading period. For example: β€˜.txt’. If no extension is found, returns the empty string.

Returns:

The path’s extension.

Implemented Traits:

  • ​Destructable
  • ​Stringable

cwd

cwd() -> Path

Gets the current directory.

Returns:

The current directory.