Module std::path

File path and glob utilities.

Manipulate file paths (join, split, check existence) and expand glob patterns to lists of matching paths.

Examples

import std::path;

fn main() {
    let dir = path.dirname("/home/user/file.txt");
    let ext = path.extension("photo.jpg");
    let result = path.glob("*.hew");
    for i in 0..result.count() {
        println(result.get(i));
    }
    result.free();
}

Contents

Functions

Function glob

pub fn glob(pattern: string) -> GlobResult

Expand a glob pattern and return all matching paths.

Examples

let files = path.glob("src/**/*.hew");

Function combine

pub fn combine(a: string, b: string) -> string

Combine two path segments with the platform path separator.

Examples

path.combine("/home/user", "file.txt")  // "/home/user/file.txt"

Function dirname

pub fn dirname(p: string) -> string

Return the directory portion of a path.

Examples

path.dirname("/home/user/file.txt")  // "/home/user"

Function basename

pub fn basename(p: string) -> string

Return the final component of a path.

Examples

path.basename("/home/user/file.txt")  // "file.txt"

Function extension

pub fn extension(p: string) -> string

Return the file extension (without the dot).

Examples

path.extension("photo.jpg")  // "jpg"

Function exists

pub fn exists(p: string) -> bool

Test whether a path exists on the filesystem.

Function is_file

pub fn is_file(p: string) -> bool

Test whether a path refers to a regular file.

Function is_dir

pub fn is_dir(p: string) -> bool

Test whether a path refers to a directory.

Function absolute

pub fn absolute(p: string) -> string

Return the absolute form of a path.

Types

Struct GlobResult

The result of a glob expansion.

Created by path.glob(pattern). Must be freed with free() when no longer needed to avoid leaking memory.

Traits

Trait GlobResultMethods

Methods available on a GlobResult.

Methods

fn count(self: Self) -> i64

Return the number of matched paths.

fn get(self: Self, index: i64) -> string

Return the matched path at the given index.

fn free(self: Self)

Release the glob result resources.