Support for well-typed paths in Haskell. Also provides ByteString based filepath manipulation.
The motivation came during development of hsfm which has a pretty strict File type, but lacks a strict Path type, e.g. for user input.
The library that came closest to my needs was path, but the API turned out to be oddly complicated for my use case, so I decided to fork it.
Similarly, posix-paths was exactly what I wanted for the low-level operations, but upstream seems dead, so it is forked as well and merged into this library.
Note: this library was written for posix systems and it will probably not support other systems.
Path Fn
for safe filename guarantees and a RelC
class~/
as relative path, because on posix level ~
is just a regular filename that does NOT point to $HOME
word8
package for save word8 literals instead of OverloadedStrings
hasTrailingPathSeparator
and dropTrailingPathSeparator
behave in the same way as their System.FilePath
counterpartequalFilePath
getSearchPath
hasParentDir
hiddenFile
isFileName
isValid
makeRelative
makeValid
normalise
splitSearchPath
stripExtension
openFd
which allows more control over the flags than its unix package counterpartgetDirectoryContents'
version that works on FdStart ghci via cabal repl
:
-- enable OverloadedStrings
:set -XOverloadedStrings
-- import HPath.IO
import HPath.IO
-- parse an absolute path
abspath <- parseAbs "/home"
-- parse a relative path (e.g. user users home directory)
relpath <- parseRel "jule"
-- concatenate paths
let newpath = abspath </> relpath
-- get file type
getFileType newpath
-- return all contents of that directory
getDirsFiles newpath
-- return all contents of the parent directory
getDirsFiles (dirname newpath)