Method in path · Path coil-stdlib

Path::basename

pub fn basename() -> Result<string, IoError>
Import
use path::{Path};
Source: src/path.hy

Returns the last component, ignoring trailing separators ("" for an empty path or /).

Called on a Path value as value.basename(…).

Returns#

Result<string, IoError>

Examples#

use path::{Path};
use tests::assert;
assert!((Path::from("a/b/c.txt").basename() ?? "") == "c.txt");
assert!((Path::from("a/b/").basename() ?? "") == "b");

See also#

  • Path: A file-system path, with helpers to take it apart and to use it.
  • Path::from: Creates a path from s as written.
  • Path::as_str: Returns the path as a string.
  • Path::join: Returns this path followed by other, with exactly one separator between them.
  • Path::dirname: Returns the path without its last component.
  • Path::extension: Returns the text after the last . of the last component, or "" when there is none.
  • Path::is_absolute: Returns true when the path starts with a separator or a Windows drive letter (C:).
  • Path::normalize: Removes . components, resolves .. against the component before it, and collapses repeated separators.
↑ ↓ navigate ↵ open