{-| The FileBase module provides basic operations that can be used on file-related objects. This module provides the utility operators '///' and 'pathsplit'. The former is used to join two path elements, providing a path separator as needed, and the latter splits a path into the directory and filename portions. > pathsplit ("foo" /// "bar" /// "cow") == ("foo/bar", "cow") > snd . pathsplit . fst . pathsplit "foo/bar/cow" == "bar" -} module FSOps.FileBase ( -- ** Utility Functions (///), pathsplit, ) where import Data.List -- |Join two path elements without duplicating path separator chars (///) :: String -> String -> String (///) dir file = if (isSuffixOf "/" dir) then dir ++ file else dir ++ "/" ++ file -- |Split a path into a tuple (directory, filename). pathsplit :: String -> (String, String) pathsplit p = let pathto = reverse . snd . rsplit . reverse filename = reverse . fst . rsplit . reverse rsplit :: String -> (String, String) rsplit ('/':rs) = rsplit rs rsplit r@_ = span (\c -> c /= '/') r in ((pathto p), (filename p))