system-filepath-0.4.10: High-level, byte-based file and directory path manipulations

Portabilityportable
Maintainerjmillikin@gmail.com
Safe HaskellNone

Filesystem.Path

Contents

Description

High‐level, byte‐based file and directory path manipulations. You probably want to import Filesystem.Path.CurrentOS instead, since it handles detecting which rules to use in the current compilation.

Synopsis

Documentation

empty :: FilePathSource

A file path with no root, directory, or filename

Basic properties

null :: FilePath -> BoolSource

null p = (p == empty)

root :: FilePath -> FilePathSource

Retrieves the FilePath’s root.

directory :: FilePath -> FilePathSource

Retrieves the FilePath’s directory. If the path is already a directory, it is returned unchanged.

parent :: FilePath -> FilePathSource

Retrieves the FilePath’s parent directory.

filename :: FilePath -> FilePathSource

Retrieve a FilePath’s filename component.

 filename "foo/bar.txt" == "bar.txt"

dirname :: FilePath -> FilePathSource

Retrieve a FilePath’s directory name. This is only the file name of the directory, not its full path.

 dirname "foo/bar/baz.txt" == "bar"
 dirname "/" == ""

Since: 0.4.1

basename :: FilePath -> FilePathSource

Retrieve a FilePath’s basename component.

 basename "foo/bar.txt" == "bar"

absolute :: FilePath -> BoolSource

Test whether a path is absolute.

relative :: FilePath -> BoolSource

Test whether a path is relative.

Basic operations

append :: FilePath -> FilePath -> FilePathSource

Appends two FilePaths. If the second path is absolute, it is returned unchanged.

concat :: [FilePath] -> FilePathSource

A fold over append.

commonPrefix :: [FilePath] -> FilePathSource

Find the greatest common prefix between a list of FilePaths.

stripPrefix :: FilePath -> FilePath -> Maybe FilePathSource

Remove a prefix from a path.

 stripPrefix "/foo/" "/foo/bar/baz.txt" == Just "bar/baz.txt"
 stripPrefix "/foo/" "/bar/baz.txt" == Nothing

This function operates on logical prefixes, rather than by counting characters. The prefix "/foo/bar/baz" is interpreted the path ("/foo/bar/", "baz"), and will be stripped accordingly:

 stripPrefix "/foo/bar/baz" "/foo/bar/baz/qux" == Nothing
 stripPrefix "/foo/bar/baz" "/foo/bar/baz.txt" == Just ".txt"

Since: 0.4.1

collapse :: FilePath -> FilePathSource

Remove intermediate "." and ".." directories from a path.

 collapse "/foo/./bar" == "/foo/bar"
 collapse "/foo/bar/../baz" == "/foo/baz"
 collapse "/foo/../../bar" == "/bar"
 collapse "./foo/bar" == "./foo/baz"

Note that if any of the elements are symbolic links, collapse may change which file the path resolves to.

Since: 0.2

splitDirectories :: FilePath -> [FilePath]Source

expand a FilePath into a list of the root name, directories, and file name

Since: 0.4.7

Extensions

extension :: FilePath -> Maybe TextSource

Get a FilePath’s last extension, or Nothing if it has no extensions.

extensions :: FilePath -> [Text]Source

Get a FilePath’s full extension list.

hasExtension :: FilePath -> Text -> BoolSource

Get whether a FilePath’s last extension is the predicate.

addExtension :: FilePath -> Text -> FilePathSource

Append an extension to the end of a FilePath.

dropExtension :: FilePath -> FilePathSource

Remove a FilePath’s last extension.

replaceExtension :: FilePath -> Text -> FilePathSource

Replace a FilePath’s last extension.

addExtensions :: FilePath -> [Text] -> FilePathSource

Append many extensions to the end of a FilePath.

dropExtensions :: FilePath -> FilePathSource

Remove all extensions from a FilePath.

replaceExtensions :: FilePath -> [Text] -> FilePathSource

Remove all extensions from a FilePath, and replace them with a new list.