std/path

The std/path module provides cross-platform utilities for manipulating file system paths. It simplifies common tasks like joining paths, extracting extensions, and finding parent directories.

Overview

Usage

import "std/path.zc"
import "std/io.zc"

fn main() {
    let p = Path::new("/home/user");
    let full_path = p.join("docs/file.txt");
    
    println(f"Full path: {full_path.c_str()}");
    
    match full_path.extension() {
        Some(ext) => { println(f"Extension: {ext}"); },
        None => { println("No extension found"); }
    }
} // full_path and p are freed automatically here

Struct Definition

struct Path {
    str: String;
}

Methods

Construction

MethodSignatureDescription
newPath::new(s: char*) -> PathCreates a new Path from a C string.
from_stringPath::from_string(s: String) -> PathCreates a Path by taking ownership of a String.
cloneclone(self) -> PathReturns a deep copy of the Path.

Manipulation

MethodSignatureDescription
joinjoin(self, other: char*) -> PathAppends other to the path using the correct directory separator.

Parsing

MethodSignatureDescription
extensionextension(self) -> Option<String>Returns the file extension (without the leading dot), if any.
file_namefile_name(self) -> Option<String>Returns the final component of the path.
parentparent(self) -> Option<Path>Returns the parent directory path.

Access

MethodSignatureDescription
c_strc_str(self) -> char*Returns the underlying C string representation.

Memory Management

MethodSignatureDescription
freefree(self)Manually frees the path's internal string memory.
Traitimpl Drop for PathAutomatically calls free() when out of scope.