IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: 1.0.0b2
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

split

def split[PathLike: PathLike, //](path: PathLike) -> Tuple[String, String]

Split a given pathname into two components: head and tail. This is useful for separating the directory path from the filename. If the input path ends with a separator, the tail component will be empty. If there is no separator in the path, the head component will be empty, and the entire path will be considered the tail. Trailing separators in the head are stripped unless the head is the root directory.

Example:

from std.os.path import split

print(split("/a/b/c.txt")) # ("/a/b", "c.txt")
print(split("/a/b/")) # ("/a/b", "")

Parameters:

  • PathLike (PathLike): The type conforming to the os.PathLike trait.

Args:

  • path (PathLike): The path to be split.

Returns:

Tuple[String, String]: A tuple containing two strings: (head, tail).