stdlib/pathView source ↗
path
22 items · generated by scribe fromstdlib/path.fd· synced 2026-11-15
Contents
- PATH_SEP: (const)
- path_sep (function)
- path_root (function)
- path_join (function)
- path_join_many (function)
- path_split (function)
- path_dirname (function)
- path_basename (function)
- path_extension (function)
- path_stem (function)
- path_set_extension (function)
- path_normalize (function)
- path_is_absolute (function)
- path_is_relative (function)
- path_has_extension (function)
- path_components (function)
- path_parent (function)
- path_depth (function)
PATH_SEP:
Path separator (always ’/’ for portability).
pub const PATH_SEP: str = "/";Defined at line 20
path_sep
Get the path separator character.
Example: assert_eq(path_sep(), ”/”);
pub fn path_sep() -> str {Returns: str
Defined at line 25
path_root
The root of a path: ”/”, “C:/”, “C:”, ”//” (UNC), or "" (relative).
Example: assert_eq(path_root(“/usr/bin”), ”/”); assert_eq(path_root(“C:\Users”), “C:/”); assert_eq(path_root(“docs/a.md”), "");
pub fn path_root(path: str) -> str {Parameters:
path:str
Returns: str
Defined at line 62
path_join
Join two path components with a separator. path_join(“foo”, “bar”) → “foo/bar” path_join(“foo/”, “bar”) → “foo/bar” path_join(“foo”, “/bar”) → “foo/bar”
Example: var p = path_join(“foo/”, “bar”); println(p); assert_eq(p, “foo/bar”); assert_eq(path_join(“foo”, “/bar”), “foo/bar”);
pub fn path_join(a: str, b: str) -> str {Parameters:
a:strb:str
Returns: str
Defined at line 92
path_join_many
Join multiple path components. path_join_many([“a”, “b”, “c”]) → “a/b/c”
Example: var parts: Vec
pub fn path_join_many(parts: Vec<str>) -> str {Parameters:
parts:Vec<str>
Returns: str
Defined at line 121
path_split
Split a path into (dirname, basename). path_split(“/a/b/c.txt”) → (“/a/b”, “c.txt”)
Example: var s = path_split(“/a/b/c.txt”); assert_eq(s.get(0), “/a/b”); assert_eq(s.get(1), “c.txt”);
pub fn path_split(path: str) -> Vec<str> {Parameters:
path:str
Returns: Vec<str>
Defined at line 143
path_dirname
Get the directory name of a path. path_dirname(“/a/b/c.txt”) → “/a/b”
Example: assert_eq(path_dirname(“/a/b/c.txt”), “/a/b”);
pub fn path_dirname(path: str) -> str {Parameters:
path:str
Returns: str
Defined at line 166
path_basename
Get the base name (file name) of a path. path_basename(“/a/b/c.txt”) → “c.txt”
Example: assert_eq(path_basename(“/a/b/c.txt”), “c.txt”); assert_eq(path_basename(“C:\dir\x.fd”), “x.fd”);
pub fn path_basename(path: str) -> str {Parameters:
path:str
Returns: str
Defined at line 191
path_extension
Get the file extension (including the dot). path_extension(“file.txt”) → “.txt” path_extension(“file”) → "" path_extension(“file.tar.gz”) → “.gz”
Example: assert_eq(path_extension(“file.tar.gz”), “.gz”); assert_eq(path_extension(“Makefile”), "");
pub fn path_extension(path: str) -> str {Parameters:
path:str
Returns: str
Defined at line 213
path_stem
Get the file name without extension. path_stem(“file.txt”) → “file” path_stem(“file.tar.gz”) → “file.tar”
Example: assert_eq(path_stem(“dir/file.tar.gz”), “file.tar”);
pub fn path_stem(path: str) -> str {Parameters:
path:str
Returns: str
Defined at line 229
path_set_extension
Change the extension of a path. path_set_extension(“file.txt”, “.md”) → “file.md” path_set_extension(“file”, “.txt”) → “file.txt”
Example: assert_eq(path_set_extension(“notes.txt”, “.md”), “notes.md”); assert_eq(path_set_extension(“notes”, “.txt”), “notes.txt”);
pub fn path_set_extension(path: str, ext: str) -> str {Parameters:
path:strext:str
Returns: str
Defined at line 245
path_normalize
Normalize a path by resolving ”.” and ”..” components. path_normalize(“a/./b/../c”) → “a/c” path_normalize(“/a/b/../c”) → “/a/c”
Example: assert_eq(path_normalize(“a/./b/../c”), “a/c”); assert_eq(path_normalize(“/a/b/../../c”), “/c”);
pub fn path_normalize(path0: str) -> str {Parameters:
path0:str
Returns: str
Defined at line 264
path_is_absolute
Check if a path is absolute.
Example: assert(path_is_absolute(“/etc”)); assert(path_is_absolute(“C:/Windows”)); assert(!path_is_absolute(“src/main.fd”));
pub fn path_is_absolute(path: str) -> bool {Parameters:
path:str
Returns: bool
Defined at line 336
path_is_relative
Check if a path is relative.
Example: assert(path_is_relative(“src/main.fd”));
pub fn path_is_relative(path: str) -> bool {Parameters:
path:str
Returns: bool
Defined at line 352
path_has_extension
Check if a path has the given extension.
Example: assert(path_has_extension(“main.fd”, “.fd”)); assert(!path_has_extension(“main.fd”, “.rs”));
pub fn path_has_extension(path: str, ext: str) -> bool {Parameters:
path:strext:str
Returns: bool
Defined at line 361
path_components
Split a path into its components. path_components(“/a/b/c”) → ["", “a”, “b”, “c”]
Example: var c = path_components(“a/b/c”); assert_eq(c.len(), 3); assert_eq(c.get(2), “c”);
pub fn path_components(path: str) -> Vec<str> {Parameters:
path:str
Returns: Vec<str>
Defined at line 375
path_parent
Get the parent directory (same as dirname but handles trailing slashes).
Example: assert_eq(path_parent(“/a/b/”), “/a”);
pub fn path_parent(path: str) -> str {Parameters:
path:str
Returns: str
Defined at line 383
path_depth
Get the number of path components.
Example: assert_eq(path_depth(“a/b/../c/d”), 3);
pub fn path_depth(path: str) -> i64 {Parameters:
path:str
Returns: i64
Defined at line 395
Generated by scribe, the Fides documentation generator