FileSystem.Path

A path represents the location of a file or directory in a filesystem.

type alias Path =
{ root : String
, directory : Array String
, filename : String
, extension : String
}

A cross-platform representation of a filesystem path.

If root is empty, it means that the path is relative to the working directory. On posix-compatible systems (Linux, Mac...), the root value is "/" if not empty. On Windows, the root refers to the specific disk that the path applies to.

filename (and extension) refers to the last part of a path. It can still represent a directory.

Constructors

empty : Path

The empty Path. Normally treated as the current directory.

fromPosixString : String -> Path

Build a Path from a String. The String should represent a Posix-compatible path.

toPosixString : Path -> String

String representation of a Path for Posix systems.

fromWin32String : String -> Path

Build a Path from a String. The String should represent a Windows-compatible path.

toWin32String : Path -> String

String representation of a Path for Windows.

Query

filenameWithExtension : Path -> String

Return the filename and file extension for a Path.

"/home/me/file.md"
    |> fromPosixString
    |> filenameWithExtension
    -- returns "file.md"
parentPath : Path -> Maybe Path

Return a Path that represents the directory which holds the given Path

"/home/me/file.md"
    |> fromPosixString
    |> parentPath
    -- returns (Just "/home/me")

Manipulation

append : Path -> Path -> Path

Join two paths by appending the first Path onto the second.

prepend : Path -> Path -> Path

Join two paths by prepending the first Path onto the second.

join : Array Path -> Path

Join all paths in an Array.