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

Portabilityportable
Maintainerjmillikin@gmail.com

System.FilePath.Rules

Contents

Description

 

Synopsis

Documentation

data Rules Source

Instances

posix :: RulesSource

Linux, BSD, OS X, and other UNIX or UNIX-like operating systems.

windows :: RulesSource

Windows and DOS

Type conversions

toBytes :: Rules -> FilePath -> ByteStringSource

Convert a FilePath into a strict ByteString, suitable for passing to OS libraries.

fromBytes :: Rules -> ByteString -> FilePathSource

Parse a strict ByteString, such as those received from OS libraries, into a FilePath.

toText :: Rules -> FilePath -> Either Text TextSource

Attempt to convert a FilePath to human‐readable text.

If the path is decoded successfully, the result is a Right containing the decoded text. Successfully decoded text can be converted back to the original path using fromText.

If the path cannot be decoded, the result is a Left containing an approximation of the original path. If displayed to the user, this value should be accompanied by some warning that the path has an invalid encoding. Approximated text cannot be converted back to the original path.

This function ignores the user’s locale, and assumes all file paths are encoded in UTF8. If you need to display file paths with an unusual or obscure encoding, use toBytes and then decode them manually.

Since: 0.2

fromText :: Rules -> Text -> FilePathSource

Convert human‐readable text into a FilePath.

This function ignores the user’s locale, and assumes all file paths are encoded in UTF8. If you need to create file paths with an unusual or obscure encoding, encode them manually and then use fromBytes.

Since: 0.2

Rule‐specific path properties

valid :: Rules -> FilePath -> BoolSource

Check if a FilePath is valid; it must not contain any illegal characters, and must have a root appropriate to the current Rules.

splitSearchPath :: Rules -> ByteString -> [FilePath]Source

Split a search path, such as $PATH or $PYTHONPATH, into a list of FilePaths.