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

Portabilityportable
Maintainerjmillikin@gmail.com
Safe HaskellSafe-Infered

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 :: FilePath

A file path with no root, directory, or filename

Basic properties

null :: FilePath -> Bool

null p = (p == empty)

root :: FilePath -> FilePath

Retrieves the FilePath’s root.

directory :: FilePath -> FilePath

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

parent :: FilePath -> FilePath

Retrieves the FilePath’s parent directory.

filename :: FilePath -> FilePath

Retrieve a FilePath’s filename component.

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

dirname :: FilePath -> FilePath

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 -> FilePath

Retrieve a FilePath’s basename component.

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

absolute :: FilePath -> Bool

Test whether a path is absolute.

relative :: FilePath -> Bool

Test whether a path is relative.

Basic operations

append :: FilePath -> FilePath -> FilePath

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

(</>) :: FilePath -> FilePath -> FilePath

An alias for append.

concat :: [FilePath] -> FilePath

A fold over append.

commonPrefix :: [FilePath] -> FilePath

Find the greatest common prefix between a list of FilePaths.

collapse :: FilePath -> FilePath

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

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

Since: 0.2

Extensions

extension :: FilePath -> Maybe Text

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

extensions :: FilePath -> [Text]

Get a FilePath’s full extension list.

hasExtension :: FilePath -> Text -> Bool

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

addExtension :: FilePath -> Text -> FilePath

Append an extension to the end of a FilePath.

(<.>) :: FilePath -> Text -> FilePath

An alias for addExtension.

dropExtension :: FilePath -> FilePath

Remove a FilePath’s last extension.

replaceExtension :: FilePath -> Text -> FilePath

Replace a FilePath’s last extension.

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

Append many extensions to the end of a FilePath.

dropExtensions :: FilePath -> FilePath

Remove all extensions from a FilePath.

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

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

splitExtensions :: FilePath -> (FilePath, [Text])

splitExtensions p = (dropExtensions p, extensions p)