Skip to content
CShift0.32

Path

Struct · namespace System

struct Path

File names and paths, as strings: Path.Combine("src", "main.cshift"), Path.GetExtension(file), …

Paths may use / or \; the functions return / separators unless they say otherwise (Path.ToNative). Nothing here touches the file system except Path.GetFullPath and Path.GetRelativePath, which read the current directory.

Name Description
Combine Joins two path parts with ‘/’ (an empty part is ignored, an absolute second part is returned as it is).
Normalize All separators of path as /.
ToNative The path with the separators of the operating system (for commands that are run by the shell).
GetDirectory The directory part: “a/b/c.txt” -> “a/b”, “c.txt” -> “”.
GetFileName The file name: “a/b/c.txt” -> “c.txt”.
GetExtension The extension including the dot: “c.txt” -> “.txt”, “c” -> “”.
GetStem The file name without directory and extension: “a/b/c.txt” -> “c”.
ChangeExtension The same path with another extension: ChangeExtension("a/b.c", ".o") (or "o") is "a/b.o".
IsRooted Whether path is absolute: "/x", "\\x" and "C:/x" are.
GetFullPath The absolute path, with ‘/’ separators and without “.” and “..” parts (relative paths start at the current directory).
GetRelativePath The path of ‘path’ relative to the directory ‘relativeTo’ (“../lib/a.txt”); both are made absolute first.
static string Combine(StringSlice a, StringSlice b)

Joins two path parts with ‘/’ (an empty part is ignored, an absolute second part is returned as it is).

static string Normalize(StringSlice path)

All separators of path as /.

static string ToNative(StringSlice path)

The path with the separators of the operating system (for commands that are run by the shell).

static string GetDirectory(StringSlice path)

The directory part: “a/b/c.txt” -> “a/b”, “c.txt” -> “”.

static string GetFileName(StringSlice path)

The file name: “a/b/c.txt” -> “c.txt”.

static string GetExtension(StringSlice path)

The extension including the dot: “c.txt” -> “.txt”, “c” -> “”.

static string GetStem(StringSlice path)

The file name without directory and extension: “a/b/c.txt” -> “c”.

static string ChangeExtension(StringSlice path, StringSlice extension)

The same path with another extension: ChangeExtension("a/b.c", ".o") (or "o") is "a/b.o".

static bool IsRooted(StringSlice path)

Whether path is absolute: "/x", "\\x" and "C:/x" are.

Since 0.04

static string GetFullPath(StringSlice path)

The absolute path, with ‘/’ separators and without “.” and “..” parts (relative paths start at the current directory).

Since 0.04

static string GetRelativePath(StringSlice relativeTo, StringSlice path)

The path of ‘path’ relative to the directory ‘relativeTo’ (“../lib/a.txt”); both are made absolute first. On another drive the absolute path is returned.

Since 0.04