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.

Function strip_trailing_slash

fn strip_trailing_slash(p: String) -> String

Strip a single trailing slash from a path, preserving the root /.

Function last_slash_pos

fn last_slash_pos(s: String) -> i32

Return the index of the last / in s, or -1 if none.

Function last_dot_pos

fn last_dot_pos(s: String) -> i32

Return the index of the last . in s, or -1 if none.

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: GlobResult) -> i32 fn get(self: GlobResult, index: i32) -> String fn free(self: GlobResult)