std.path
Return the absolute path of path.
Return the absolute path of path.
Return the absolute path of path.
use std.path;
fn main() throws {
try path.absolute("/home/username/.bashrc"); // "/home/username/.bashrc"
// If path is relative, it will be relative to current working directory.
// If current working directory is "/home/username", then:
try path.absolute("test.nv"); // "/home/username/test.nv"
}
Return true if path is exists, false otherwise.
Return true if path is exists, false otherwise.
Return true if path is exists, false otherwise.
use std.path;
path.exists("~/.bashrc"); // true
path.exists("/home/username/.bashrc"); // true
path.exists("/a/not/exist/path"); // false
Return extension of a path, without .
.
Return extension of a path, without .
.
Return extension of a path, without .
.
use std.path;
assert_eq path.extension("/home/username/.bashrc"), nil;
assert_eq path.extension("/home/username/.bashrc/"), nil;
assert_eq path.extension("/home/username/test.nv"), "nv";
assert_eq path.extension("/home/username/test"), nil;
assert_eq path.extension("/home/username/test.html.erb"), "erb";
Returns the final component of the Path, if there is one.
Returns the final component of the Path, if there is one.
Returns the final component of the Path, if there is one.
If the path is a normal file, this is the file name. If it’s the path of a directory, this is the directory name.
use std.path;
assert_eq path.file_name("/home/username/.bashrc"), ".bashrc";
assert_eq path.file_name("/home/username"), "username";
assert_eq path.file_name("/"), nil;
is_absolute
pub fn is_absolute(path: string): bool
Return true
if the path is absolute, false
otherwise.
is_absolute
pub fn is_absolute(path: string): bool
Return true
if the path is absolute, false
otherwise.
Return true
if the path is absolute, false
otherwise.
use std.path;
path.is_absolute("/home/username/.bashrc"); // true
path.is_absolute("test.nv"); // false
Check if path is a directory.
Check if path is a directory.
Check if path is a directory.
use std.path;
path.is_dir("/home/username"); // true
path.is_dir("/home/username/.bashrc"); // false
Check if path is a file.
Check if path is a file.
Check if path is a file.
use std.path;
path.is_file("/home/username"); // false
path.is_file("/home/username/.bashrc"); // true
is_symlink
pub fn is_symlink(path: string): bool
Return true
if the path is a symlink, false
otherwise.
is_symlink
pub fn is_symlink(path: string): bool
Return true
if the path is a symlink, false
otherwise.
Return true
if the path is a symlink, false
otherwise.
If path is not exists, return false
.
use std.path;
// Create a symlink `ln -s /home/username/.bashrc /home/username/.bashrc-symlink`
path.is_symlink("/home/username/.bashrc"); // false
path.is_symlink("/home/username/.bashrc-symlink"); // true
Join two paths together.
Join two paths together.
Join two paths together.
The first argument is the base path, and the rest are the parts to join to it.
use std.path;
assert_eq path.join("/home/username", ".bashrc"), "/home/username/.bashrc";
assert_eq path.join("/home", "username", "test.nv"), "/home/username/test.nv";
Returns the Path
without its final component, if there is one.
Returns the Path
without its final component, if there is one.
Returns the Path
without its final component, if there is one.
use std.path;
assert_eq path.parent("/home/username/.bashrc"), "/home/username";
assert_eq path.parent("/home/username"), "/home";
assert_eq path.parent("/"), nil;
Returns the segments of a path.
Returns the segments of a path.
Returns the segments of a path.
use std.path;
use std.fs;
assert_eq path.segments("/home/username/.bashrc"), [fs.MAIN_SEPARATOR, "home", "username", ".bashrc"];
assert_eq path.segments("/home/username"), [fs.MAIN_SEPARATOR, "home", "username"];
assert_eq path.segments("/home/username/"), [fs.MAIN_SEPARATOR, "home", "username"];