-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Type-safe replacement for System.FilePath etc -- -- This package provides type-safe access to filepath manipulations. -- -- System.Path is designed to be used instead of -- System.FilePath. (It is intended to provide versions of -- functions from that module which have equivalent functionality but are -- more typesafe). System.Path.Directory is a companion module -- providing a type-safe alternative to System.Directory. -- -- The heart of this module is the Path ar fd abstract -- type which represents file and directory paths. The idea is that there -- are two phantom type parameters - the first should be Abs or -- Rel, and the second File or Dir. A number of type -- synonyms are provided for common types: -- --
-- type AbsFile = Path Abs File -- type RelFile = Path Rel File -- type AbsDir = Path Abs Dir -- type RelDir = Path Rel Dir -- -- type AbsPath fd = Path Abs fd -- type RelPath fd = Path Rel fd -- type FilePath ar = Path ar File -- type DirPath ar = Path ar Dir ---- -- The type of the combine (aka </>) function gives -- the idea: -- --
-- (</>) :: DirPath ar -> RelPath fd -> Path ar fd ---- -- Together this enables us to give more meaningful types to a lot of the -- functions, and (hopefully) catch a bunch more errors at compile time. -- -- Overloaded string literals are supported, so with the -- OverloadedStrings extension enabled, you can: -- --
-- f :: FilePath ar -- f = "tmp" </> "someFile" <.> "ext" ---- -- If you don't want to use OverloadedStrings, you can use the -- construction fns: -- --
-- f :: FilePath ar -- f = asDirPath "tmp" </> asFilePath "someFile" <.> "ext" ---- -- or... -- --
-- f :: FilePath ar -- f = asPath "tmp" </> asPath "someFile" <.> "ext" ---- -- or just... -- --
-- f :: FilePath ar -- f = asPath "tmp/someFile.ext" ---- -- One point to note is that whether one of these is interpreted as an -- absolute or a relative path depends on the type at which it is used: -- --
-- *System.Path> f :: AbsFile -- /tmp/someFile.ext -- *System.Path> f :: RelFile -- tmp/someFile.ext ---- -- You will typically want to import as follows: -- --
-- import Prelude hiding (FilePath) -- import System.Path -- import System.Path.Directory -- import System.Path.IO ---- -- The basic API (and properties satisfied) are heavily influenced by -- Neil Mitchell's System.FilePath module. @package pathtype @version 0.5.4.2 -- | This module provides type-safe access to filepath manipulations. -- -- Normally you would import Path (which will use the default -- implementation for the host platform) instead of this. However, -- importing this explicitly allows for manipulation of non-native paths. module System.Path.Windows -- | This is the main filepath abstract datatype data Path ar fd data Abs data Rel data File data Dir type AbsFile = Path Abs File type RelFile = Path Rel File type AbsDir = Path Abs Dir type RelDir = Path Rel Dir type AbsPath fd = Path Abs fd type RelPath fd = Path Rel fd type FilePath ar = Path ar File type DirPath ar = Path ar Dir -- | This class allows selective behaviour for absolute and relative paths -- and is mostly for internal use. class Private ar => AbsRelClass ar absRel :: AbsRelClass ar => (AbsPath fd -> a) -> (RelPath fd -> a) -> Path ar fd -> a -- | This class allows selective behaviour for file and directory paths and -- is mostly for internal use. class Private fd => FileDirClass fd fileDir :: FileDirClass fd => (FilePath ar -> a) -> (DirPath ar -> a) -> Path ar fd -> a -- | Convert the Path into a plain String. This is simply an -- alias for show. getPathString :: AbsRelClass ar => Path ar fd -> String rootDir :: AbsDir currentDir :: RelDir -- | Use a String as a Path whose type is determined by its -- context. -- --
-- > asPath "/tmp" == "/tmp" -- > asPath "file.txt" == "file.txt" -- > isAbsolute (asPath "/tmp" :: AbsDir) == True -- > isAbsolute (asPath "/tmp" :: RelDir) == False -- > getPathString (asPath "/tmp" :: AbsDir) == "/tmp" -- > getPathString (asPath "/tmp" :: RelDir) == "tmp" --asPath :: String -> Path ar fd -- | Use a String as a RelFile. No checking is done. -- --
-- > getPathString (asRelFile "file.txt") == "file.txt" -- > getPathString (asRelFile "/file.txt") == "file.txt" -- > getPathString (asRelFile "tmp") == "tmp" -- > getPathString (asRelFile "/tmp") == "tmp" --asRelFile :: String -> RelFile -- | Use a String as a RelDir. No checking is done. -- --
-- > getPathString (asRelDir "file.txt") == "file.txt" -- > getPathString (asRelDir "/file.txt") == "file.txt" -- > getPathString (asRelDir "tmp") == "tmp" -- > getPathString (asRelDir "/tmp") == "tmp" --asRelDir :: String -> RelDir -- | Use a String as an AbsFile. No checking is done. -- --
-- > getPathString (asAbsFile "file.txt") == "/file.txt" -- > getPathString (asAbsFile "/file.txt") == "/file.txt" -- > getPathString (asAbsFile "tmp") == "/tmp" -- > getPathString (asAbsFile "/tmp") == "/tmp" --asAbsFile :: String -> AbsFile -- | Use a String as an AbsDir. No checking is done. -- --
-- > getPathString (asAbsDir "file.txt") == "/file.txt" -- > getPathString (asAbsDir "/file.txt") == "/file.txt" -- > getPathString (asAbsDir "tmp") == "/tmp" -- > getPathString (asAbsDir "/tmp") == "/tmp" --asAbsDir :: String -> AbsDir -- | Use a String as a 'RelPath fd'. No checking is done. asRelPath :: String -> RelPath fd -- | Use a String as an 'AbsPath fd'. No checking is done. asAbsPath :: String -> AbsPath fd -- | Use a String as a 'FilePath ar'. No checking is done. asFilePath :: String -> FilePath ar -- | Use a String as a 'DirPath ar'. No checking is done. asDirPath :: String -> DirPath ar -- | Examines the supplied string and constructs an absolute or relative -- path as appropriate. -- --
-- > either id (const "fred") (mkPathAbsOrRel "/tmp") == "/tmp" -- > either id (const "fred") (mkPathAbsOrRel "tmp") == "fred" --mkPathAbsOrRel :: String -> Either (AbsPath fd) (RelPath fd) -- | Searches for a file or directory with the supplied path string and -- returns a File or Dir path as appropriate. If neither -- exists at the supplied path, Nothing is returned. mkPathFileOrDir :: AbsRelClass ar => String -> IO (Maybe (Either (FilePath ar) (DirPath ar))) -- | Convert a String into an AbsPath by interpreting it as -- relative to the supplied directory if necessary. -- --
-- > mkAbsPath "/tmp" "foo.txt" == "/tmp/foo.txt" -- > mkAbsPath "/tmp" "/etc/foo.txt" == "/etc/foo.txt" --mkAbsPath :: AbsDir -> String -> AbsPath fd -- | Convert a String into an AbsPath by interpreting it as -- relative to the cwd if necessary. mkAbsPathFromCwd :: String -> IO (AbsPath fd) -- | Join an (absolute or relative) directory path with a relative (file or -- directory) path to form a new path. (>) :: DirPath ar -> RelPath fd -> Path ar fd -- | We only allow files (and not directories) to have extensions added by -- this function. This is because it's the vastly common case and an -- attempt to add one to a directory will - more often than not - -- represent an error. We don't however want to prevent the corresponding -- operation on directories, and so we provide a function that is more -- flexible: genericAddExtension. (<.>) :: FilePath ar -> String -> FilePath ar -- | Add an extension, even if there is already one there. E.g. -- addExtension "foo.txt" "bat" -> "foo.txt.bat". -- --
-- > addExtension "file.txt" "bib" == "file.txt.bib" -- > addExtension "file." ".bib" == "file..bib" -- > addExtension "file" ".bib" == "file.bib" -- > takeFileName (addExtension "" "ext") == ".ext" --addExtension :: FilePath ar -> String -> FilePath ar -- | Join an (absolute or relative) directory path with a relative (file or -- directory) path to form a new path. combine :: DirPath ar -> RelPath fd -> Path ar fd -- | Remove last extension, and the "." preceding it. -- --
-- > dropExtension x == fst (splitExtension x) --dropExtension :: FilePath ar -> FilePath ar -- | Drop all extensions -- --
-- > not $ hasAnExtension (dropExtensions x) --dropExtensions :: FilePath ar -> FilePath ar dropFileName :: Path ar fd -> DirPath ar -- | Set the extension of a file, overwriting one if already present. -- --
-- > replaceExtension "file.txt" ".bob" == "file.bob" -- > replaceExtension "file.txt" "bob" == "file.bob" -- > replaceExtension "file" ".bob" == "file.bob" -- > replaceExtension "file.txt" "" == "file" -- > replaceExtension "file.fred.bob" "txt" == "file.fred.txt" --replaceExtension :: FilePath ar -> String -> FilePath ar replaceBaseName :: Path ar fd -> String -> Path ar fd replaceDirectory :: Path ar1 fd -> DirPath ar2 -> Path ar2 fd replaceFileName :: Path ar fd -> String -> Path ar fd -- | Split on the extension. addExtension is the inverse. -- --
-- > uncurry (<.>) (splitExtension x) == x
-- > uncurry addExtension (splitExtension x) == x
-- > splitExtension "file.txt" == ("file",".txt")
-- > splitExtension "file" == ("file","")
-- > splitExtension "file/file.txt" == ("file/file",".txt")
-- > splitExtension "file.txt/boris" == ("file.txt/boris","")
-- > splitExtension "file.txt/boris.ext" == ("file.txt/boris",".ext")
-- > splitExtension "file/path.txt.bob.fred" == ("file/path.txt.bob",".fred")
--
splitExtension :: FilePath ar -> (FilePath ar, String)
-- | Split on all extensions
--
--
-- > splitExtensions "file.tar.gz" == ("file",".tar.gz")
--
splitExtensions :: FilePath ar -> (FilePath ar, String)
-- | Path must not be empty
splitFileName :: Path ar fd -> (DirPath ar, RelPath fd)
-- | Get the basename of a file
--
-- -- > takeBaseName "/tmp/somedir/myfile.txt" == "myfile" -- > takeBaseName "./myfile.txt" == "myfile" -- > takeBaseName "myfile.txt" == "myfile" --takeBaseName :: Path ar fd -> RelPath fd takeDirectory :: Path ar fd -> DirPath ar -- | Get the extension of a file, returns "" for no extension, -- .ext otherwise. -- --
-- > takeExtension x == snd (splitExtension x) -- > takeExtension (addExtension x "ext") == ".ext" -- > takeExtension (replaceExtension x "ext") == ".ext" --takeExtension :: FilePath ar -> String -- | Get all extensions -- --
-- > takeExtensions "file.tar.gz" == ".tar.gz" --takeExtensions :: FilePath ar -> String -- | Get the filename component of a file path (ie stripping all parent -- dirs) -- --
-- > takeFileName "/tmp/somedir/myfile.txt" == "myfile.txt" -- > takeFileName "./myfile.txt" == "myfile.txt" -- > takeFileName "myfile.txt" == "myfile.txt" --takeFileName :: Path ar fd -> RelPath fd -- | Check whether two strings are equal as file paths. -- --
-- > equalFilePath "/tmp/" "/tmp" == True -- > equalFilePath "/tmp" "tmp" == False --equalFilePath :: String -> String -> Bool -- | Constructs a Path from a list of components. -- --
-- > joinPath ["/tmp","someDir","file.txt"] == "/tmp/someDir/file.txt" -- > (joinPath ["/tmp","someDir","file.txt"] :: RelFile) == "tmp/someDir/file.txt" --joinPath :: [String] -> Path ar fd -- | Currently just transforms: -- --
-- > normalise "/tmp/fred/./jim/./file" == "/tmp/fred/jim/file" --normalise :: Path ar fd -> Path ar fd -- | Deconstructs a path into its components. -- --
-- > splitPath ("/tmp/someDir/myfile.txt" :: AbsDir) == (["tmp","someDir","myfile.txt"],Nothing)
-- > splitPath ("/tmp/someDir/myfile.txt" :: AbsFile) == (["tmp","someDir"],Just "myfile.txt")
-- > splitPath (asAbsFile "/tmp/someDir/myfile.txt") == (["tmp","someDir"],Just "myfile.txt")
--
splitPath :: FileDirClass fd => Path ar fd -> ([RelDir], Maybe RelFile)
-- | This function can be used to construct a relative path by removing the
-- supplied AbsDir from the front. It is a runtime error if
-- the supplied AbsPath doesn't start with the AbsDir.
--
-- -- > makeRelative "/tmp/somedir" "/tmp/somedir/anotherdir/file.txt" == "anotherdir/file.txt" --makeRelative :: AbsDir -> AbsPath fd -> RelPath fd -- | Joins an absolute directory with a relative path to construct a new -- absolute path. -- --
-- > makeAbsolute "/tmp" "file.txt" == "/tmp/file.txt" -- > makeAbsolute "/tmp" "adir/file.txt" == "/tmp/adir/file.txt" --makeAbsolute :: AbsDir -> RelPath fd -> AbsPath fd -- | Converts a relative path into an absolute one by prepending the -- current working directory. makeAbsoluteFromCwd :: RelPath fd -> IO (AbsPath fd) -- | As for makeAbsolute, but for use when the path may already be -- absolute (in which case it is left unchanged). -- --
-- > genericMakeAbsolute "/tmp" (asRelFile "file.txt") == "/tmp/file.txt" -- > genericMakeAbsolute "/tmp" (asRelFile "adir/file.txt") == "/tmp/adir/file.txt" -- > genericMakeAbsolute "/tmp" (asAbsFile "adir/file.txt") == "/adir/file.txt" -- > genericMakeAbsolute "/tmp" (asAbsFile "/adir/file.txt") == "/adir/file.txt" --genericMakeAbsolute :: AbsRelClass ar => AbsDir -> Path ar fd -> AbsPath fd -- | As for makeAbsoluteFromCwd, but for use when the path may -- already be absolute (in which case it is left unchanged). genericMakeAbsoluteFromCwd :: AbsRelClass ar => Path ar fd -> IO (AbsPath fd) -- | Map over the components of the path. -- --
-- > pathMap (map toLower) "/tmp/Reports/SpreadSheets" == "/tmp/reports/spreadsheets" --pathMap :: (String -> String) -> Path ar fd -> Path ar fd -- | Test whether a Path ar fd is absolute. -- --
-- > isAbsolute (asAbsFile "fred") == True -- > isAbsolute (asRelFile "fred") == False -- > isAbsolute (asAbsFile "/fred") == True -- > isAbsolute (asRelFile "/fred") == False --isAbsolute :: AbsRelClass ar => Path ar fd -> Bool -- | Test whether the String would correspond to an absolute path if -- interpreted as a Path. isAbsoluteString :: String -> Bool -- | Invariant - this should return True iff arg is of type Path -- Rel _ -- --
-- isRelative = not . isAbsolute --isRelative :: AbsRelClass ar => Path ar fd -> Bool -- | Test whether the String would correspond to a relative path if -- interpreted as a Path. -- --
-- isRelativeString = not . isAbsoluteString --isRelativeString :: String -> Bool -- | Does the given filename have an extension? -- --
-- > null (takeExtension x) == not (hasAnExtension x) --hasAnExtension :: FilePath ar -> Bool -- | Does the given filename have the given extension? -- --
-- > hasExtension ".hs" "MyCode.hs" == True -- > hasExtension ".hs" "MyCode.hs.bak" == False -- > hasExtension ".hs" "MyCode.bak.hs" == True --hasExtension :: String -> FilePath ar -> Bool -- | This is largely for FilePath compatability addTrailingPathSeparator :: String -> String -- | This is largely for FilePath compatability dropTrailingPathSeparator :: String -> String -- | File extension character -- --
-- > extSeparator == '.' --extSeparator :: Char -- | This is largely for FilePath compatability hasTrailingPathSeparator :: String -> Bool -- | The character that separates directories. In the case where more than -- one character is possible, pathSeparator is the 'ideal' one. -- --
-- > isPathSeparator pathSeparator --pathSeparator :: Char -- | The list of all possible separators. -- --
-- > pathSeparator `elem` pathSeparators --pathSeparators :: [Char] -- | The character that is used to separate the entries in the $PATH -- environment variable. searchPathSeparator :: Char -- | Is the character an extension character? -- --
-- > isExtSeparator a == (a == extSeparator) --isExtSeparator :: Char -> Bool -- | Rather than using (== pathSeparator), use this. Test -- if something is a path separator. -- --
-- > isPathSeparator a == (a `elem` pathSeparators) --isPathSeparator :: Char -> Bool -- | Is the character a file separator? -- --
-- > isSearchPathSeparator a == (a == searchPathSeparator) --isSearchPathSeparator :: Char -> Bool -- | This is a more flexible variant of addExtension / -- <.> which can work with files or directories -- --
-- > genericAddExtension "/" "x" == "/.x" --genericAddExtension :: Path ar fd -> String -> Path ar fd genericDropExtension :: Path ar fd -> Path ar fd genericDropExtensions :: Path ar fd -> Path ar fd genericSplitExtension :: Path ar fd -> (Path ar fd, String) genericSplitExtensions :: Path ar fd -> (Path ar fd, String) genericTakeExtension :: Path ar fd -> String genericTakeExtensions :: Path ar fd -> String instance GHC.Classes.Ord (System.Path.Windows.Path ar fd) instance GHC.Classes.Eq (System.Path.Windows.Path ar fd) instance GHC.Classes.Ord System.Path.Windows.PathComponent instance GHC.Classes.Eq System.Path.Windows.PathComponent instance GHC.Show.Show System.Path.Windows.PathComponent instance System.Path.Windows.Private System.Path.Windows.Abs instance System.Path.Windows.Private System.Path.Windows.Rel instance System.Path.Windows.Private System.Path.Windows.File instance System.Path.Windows.Private System.Path.Windows.Dir instance System.Path.Windows.AbsRelClass System.Path.Windows.Abs instance System.Path.Windows.AbsRelClass System.Path.Windows.Rel instance System.Path.Windows.FileDirClass System.Path.Windows.File instance System.Path.Windows.FileDirClass System.Path.Windows.Dir instance System.Path.Windows.AbsRelClass ar => GHC.Show.Show (System.Path.Windows.Path ar fd) instance System.Path.Windows.AbsRelClass ar => GHC.Read.Read (System.Path.Windows.Path ar fd) instance Data.String.IsString (System.Path.Windows.Path ar fd) instance Test.QuickCheck.Arbitrary.Arbitrary System.Path.Windows.PathComponent instance Test.QuickCheck.Arbitrary.Arbitrary (System.Path.Windows.Path ar System.Path.Windows.File) instance Test.QuickCheck.Arbitrary.Arbitrary (System.Path.Windows.Path ar System.Path.Windows.Dir) -- | This module provides type-safe access to filepath manipulations. -- -- Normally you would import Path (which will use the default -- implementation for the host platform) instead of this. However, -- importing this explicitly allows for manipulation of non-native paths. module System.Path.Posix -- | This is the main filepath abstract datatype data Path ar fd data Abs data Rel data File data Dir type AbsFile = Path Abs File type RelFile = Path Rel File type AbsDir = Path Abs Dir type RelDir = Path Rel Dir type AbsPath fd = Path Abs fd type RelPath fd = Path Rel fd type FilePath ar = Path ar File type DirPath ar = Path ar Dir -- | This class allows selective behaviour for absolute and relative paths -- and is mostly for internal use. class Private ar => AbsRelClass ar absRel :: AbsRelClass ar => (AbsPath fd -> a) -> (RelPath fd -> a) -> Path ar fd -> a -- | This class allows selective behaviour for file and directory paths and -- is mostly for internal use. class Private fd => FileDirClass fd fileDir :: FileDirClass fd => (FilePath ar -> a) -> (DirPath ar -> a) -> Path ar fd -> a -- | Convert the Path into a plain String. This is simply an -- alias for show. getPathString :: AbsRelClass ar => Path ar fd -> String rootDir :: AbsDir currentDir :: RelDir -- | Use a String as a Path whose type is determined by its -- context. -- --
-- > asPath "/tmp" == "/tmp" -- > asPath "file.txt" == "file.txt" -- > isAbsolute (asPath "/tmp" :: AbsDir) == True -- > isAbsolute (asPath "/tmp" :: RelDir) == False -- > getPathString (asPath "/tmp" :: AbsDir) == "/tmp" -- > getPathString (asPath "/tmp" :: RelDir) == "tmp" --asPath :: String -> Path ar fd -- | Use a String as a RelFile. No checking is done. -- --
-- > getPathString (asRelFile "file.txt") == "file.txt" -- > getPathString (asRelFile "/file.txt") == "file.txt" -- > getPathString (asRelFile "tmp") == "tmp" -- > getPathString (asRelFile "/tmp") == "tmp" --asRelFile :: String -> RelFile -- | Use a String as a RelDir. No checking is done. -- --
-- > getPathString (asRelDir "file.txt") == "file.txt" -- > getPathString (asRelDir "/file.txt") == "file.txt" -- > getPathString (asRelDir "tmp") == "tmp" -- > getPathString (asRelDir "/tmp") == "tmp" --asRelDir :: String -> RelDir -- | Use a String as an AbsFile. No checking is done. -- --
-- > getPathString (asAbsFile "file.txt") == "/file.txt" -- > getPathString (asAbsFile "/file.txt") == "/file.txt" -- > getPathString (asAbsFile "tmp") == "/tmp" -- > getPathString (asAbsFile "/tmp") == "/tmp" --asAbsFile :: String -> AbsFile -- | Use a String as an AbsDir. No checking is done. -- --
-- > getPathString (asAbsDir "file.txt") == "/file.txt" -- > getPathString (asAbsDir "/file.txt") == "/file.txt" -- > getPathString (asAbsDir "tmp") == "/tmp" -- > getPathString (asAbsDir "/tmp") == "/tmp" --asAbsDir :: String -> AbsDir -- | Use a String as a 'RelPath fd'. No checking is done. asRelPath :: String -> RelPath fd -- | Use a String as an 'AbsPath fd'. No checking is done. asAbsPath :: String -> AbsPath fd -- | Use a String as a 'FilePath ar'. No checking is done. asFilePath :: String -> FilePath ar -- | Use a String as a 'DirPath ar'. No checking is done. asDirPath :: String -> DirPath ar -- | Examines the supplied string and constructs an absolute or relative -- path as appropriate. -- --
-- > either id (const "fred") (mkPathAbsOrRel "/tmp") == "/tmp" -- > either id (const "fred") (mkPathAbsOrRel "tmp") == "fred" --mkPathAbsOrRel :: String -> Either (AbsPath fd) (RelPath fd) -- | Searches for a file or directory with the supplied path string and -- returns a File or Dir path as appropriate. If neither -- exists at the supplied path, Nothing is returned. mkPathFileOrDir :: AbsRelClass ar => String -> IO (Maybe (Either (FilePath ar) (DirPath ar))) -- | Convert a String into an AbsPath by interpreting it as -- relative to the supplied directory if necessary. -- --
-- > mkAbsPath "/tmp" "foo.txt" == "/tmp/foo.txt" -- > mkAbsPath "/tmp" "/etc/foo.txt" == "/etc/foo.txt" --mkAbsPath :: AbsDir -> String -> AbsPath fd -- | Convert a String into an AbsPath by interpreting it as -- relative to the cwd if necessary. mkAbsPathFromCwd :: String -> IO (AbsPath fd) -- | Join an (absolute or relative) directory path with a relative (file or -- directory) path to form a new path. (>) :: DirPath ar -> RelPath fd -> Path ar fd -- | We only allow files (and not directories) to have extensions added by -- this function. This is because it's the vastly common case and an -- attempt to add one to a directory will - more often than not - -- represent an error. We don't however want to prevent the corresponding -- operation on directories, and so we provide a function that is more -- flexible: genericAddExtension. (<.>) :: FilePath ar -> String -> FilePath ar -- | Add an extension, even if there is already one there. E.g. -- addExtension "foo.txt" "bat" -> "foo.txt.bat". -- --
-- > addExtension "file.txt" "bib" == "file.txt.bib" -- > addExtension "file." ".bib" == "file..bib" -- > addExtension "file" ".bib" == "file.bib" -- > takeFileName (addExtension "" "ext") == ".ext" --addExtension :: FilePath ar -> String -> FilePath ar -- | Join an (absolute or relative) directory path with a relative (file or -- directory) path to form a new path. combine :: DirPath ar -> RelPath fd -> Path ar fd -- | Remove last extension, and the "." preceding it. -- --
-- > dropExtension x == fst (splitExtension x) --dropExtension :: FilePath ar -> FilePath ar -- | Drop all extensions -- --
-- > not $ hasAnExtension (dropExtensions x) --dropExtensions :: FilePath ar -> FilePath ar dropFileName :: Path ar fd -> DirPath ar -- | Set the extension of a file, overwriting one if already present. -- --
-- > replaceExtension "file.txt" ".bob" == "file.bob" -- > replaceExtension "file.txt" "bob" == "file.bob" -- > replaceExtension "file" ".bob" == "file.bob" -- > replaceExtension "file.txt" "" == "file" -- > replaceExtension "file.fred.bob" "txt" == "file.fred.txt" --replaceExtension :: FilePath ar -> String -> FilePath ar replaceBaseName :: Path ar fd -> String -> Path ar fd replaceDirectory :: Path ar1 fd -> DirPath ar2 -> Path ar2 fd replaceFileName :: Path ar fd -> String -> Path ar fd -- | Split on the extension. addExtension is the inverse. -- --
-- > uncurry (<.>) (splitExtension x) == x
-- > uncurry addExtension (splitExtension x) == x
-- > splitExtension "file.txt" == ("file",".txt")
-- > splitExtension "file" == ("file","")
-- > splitExtension "file/file.txt" == ("file/file",".txt")
-- > splitExtension "file.txt/boris" == ("file.txt/boris","")
-- > splitExtension "file.txt/boris.ext" == ("file.txt/boris",".ext")
-- > splitExtension "file/path.txt.bob.fred" == ("file/path.txt.bob",".fred")
--
splitExtension :: FilePath ar -> (FilePath ar, String)
-- | Split on all extensions
--
--
-- > splitExtensions "file.tar.gz" == ("file",".tar.gz")
--
splitExtensions :: FilePath ar -> (FilePath ar, String)
-- | Path must not be empty
splitFileName :: Path ar fd -> (DirPath ar, RelPath fd)
-- | Get the basename of a file
--
-- -- > takeBaseName "/tmp/somedir/myfile.txt" == "myfile" -- > takeBaseName "./myfile.txt" == "myfile" -- > takeBaseName "myfile.txt" == "myfile" --takeBaseName :: Path ar fd -> RelPath fd takeDirectory :: Path ar fd -> DirPath ar -- | Get the extension of a file, returns "" for no extension, -- .ext otherwise. -- --
-- > takeExtension x == snd (splitExtension x) -- > takeExtension (addExtension x "ext") == ".ext" -- > takeExtension (replaceExtension x "ext") == ".ext" --takeExtension :: FilePath ar -> String -- | Get all extensions -- --
-- > takeExtensions "file.tar.gz" == ".tar.gz" --takeExtensions :: FilePath ar -> String -- | Get the filename component of a file path (ie stripping all parent -- dirs) -- --
-- > takeFileName "/tmp/somedir/myfile.txt" == "myfile.txt" -- > takeFileName "./myfile.txt" == "myfile.txt" -- > takeFileName "myfile.txt" == "myfile.txt" --takeFileName :: Path ar fd -> RelPath fd -- | Check whether two strings are equal as file paths. -- --
-- > equalFilePath "/tmp/" "/tmp" == True -- > equalFilePath "/tmp" "tmp" == False --equalFilePath :: String -> String -> Bool -- | Constructs a Path from a list of components. -- --
-- > joinPath ["/tmp","someDir","file.txt"] == "/tmp/someDir/file.txt" -- > (joinPath ["/tmp","someDir","file.txt"] :: RelFile) == "tmp/someDir/file.txt" --joinPath :: [String] -> Path ar fd -- | Currently just transforms: -- --
-- > normalise "/tmp/fred/./jim/./file" == "/tmp/fred/jim/file" --normalise :: Path ar fd -> Path ar fd -- | Deconstructs a path into its components. -- --
-- > splitPath ("/tmp/someDir/myfile.txt" :: AbsDir) == (["tmp","someDir","myfile.txt"],Nothing)
-- > splitPath ("/tmp/someDir/myfile.txt" :: AbsFile) == (["tmp","someDir"],Just "myfile.txt")
-- > splitPath (asAbsFile "/tmp/someDir/myfile.txt") == (["tmp","someDir"],Just "myfile.txt")
--
splitPath :: FileDirClass fd => Path ar fd -> ([RelDir], Maybe RelFile)
-- | This function can be used to construct a relative path by removing the
-- supplied AbsDir from the front. It is a runtime error if
-- the supplied AbsPath doesn't start with the AbsDir.
--
-- -- > makeRelative "/tmp/somedir" "/tmp/somedir/anotherdir/file.txt" == "anotherdir/file.txt" --makeRelative :: AbsDir -> AbsPath fd -> RelPath fd -- | Joins an absolute directory with a relative path to construct a new -- absolute path. -- --
-- > makeAbsolute "/tmp" "file.txt" == "/tmp/file.txt" -- > makeAbsolute "/tmp" "adir/file.txt" == "/tmp/adir/file.txt" --makeAbsolute :: AbsDir -> RelPath fd -> AbsPath fd -- | Converts a relative path into an absolute one by prepending the -- current working directory. makeAbsoluteFromCwd :: RelPath fd -> IO (AbsPath fd) -- | As for makeAbsolute, but for use when the path may already be -- absolute (in which case it is left unchanged). -- --
-- > genericMakeAbsolute "/tmp" (asRelFile "file.txt") == "/tmp/file.txt" -- > genericMakeAbsolute "/tmp" (asRelFile "adir/file.txt") == "/tmp/adir/file.txt" -- > genericMakeAbsolute "/tmp" (asAbsFile "adir/file.txt") == "/adir/file.txt" -- > genericMakeAbsolute "/tmp" (asAbsFile "/adir/file.txt") == "/adir/file.txt" --genericMakeAbsolute :: AbsRelClass ar => AbsDir -> Path ar fd -> AbsPath fd -- | As for makeAbsoluteFromCwd, but for use when the path may -- already be absolute (in which case it is left unchanged). genericMakeAbsoluteFromCwd :: AbsRelClass ar => Path ar fd -> IO (AbsPath fd) -- | Map over the components of the path. -- --
-- > pathMap (map toLower) "/tmp/Reports/SpreadSheets" == "/tmp/reports/spreadsheets" --pathMap :: (String -> String) -> Path ar fd -> Path ar fd -- | Test whether a Path ar fd is absolute. -- --
-- > isAbsolute (asAbsFile "fred") == True -- > isAbsolute (asRelFile "fred") == False -- > isAbsolute (asAbsFile "/fred") == True -- > isAbsolute (asRelFile "/fred") == False --isAbsolute :: AbsRelClass ar => Path ar fd -> Bool -- | Test whether the String would correspond to an absolute path if -- interpreted as a Path. isAbsoluteString :: String -> Bool -- | Invariant - this should return True iff arg is of type Path -- Rel _ -- --
-- isRelative = not . isAbsolute --isRelative :: AbsRelClass ar => Path ar fd -> Bool -- | Test whether the String would correspond to a relative path if -- interpreted as a Path. -- --
-- isRelativeString = not . isAbsoluteString --isRelativeString :: String -> Bool -- | Does the given filename have an extension? -- --
-- > null (takeExtension x) == not (hasAnExtension x) --hasAnExtension :: FilePath ar -> Bool -- | Does the given filename have the given extension? -- --
-- > hasExtension ".hs" "MyCode.hs" == True -- > hasExtension ".hs" "MyCode.hs.bak" == False -- > hasExtension ".hs" "MyCode.bak.hs" == True --hasExtension :: String -> FilePath ar -> Bool -- | This is largely for FilePath compatability addTrailingPathSeparator :: String -> String -- | This is largely for FilePath compatability dropTrailingPathSeparator :: String -> String -- | File extension character -- --
-- > extSeparator == '.' --extSeparator :: Char -- | This is largely for FilePath compatability hasTrailingPathSeparator :: String -> Bool -- | The character that separates directories. In the case where more than -- one character is possible, pathSeparator is the 'ideal' one. -- --
-- > isPathSeparator pathSeparator --pathSeparator :: Char -- | The list of all possible separators. -- --
-- > pathSeparator `elem` pathSeparators --pathSeparators :: [Char] -- | The character that is used to separate the entries in the $PATH -- environment variable. searchPathSeparator :: Char -- | Is the character an extension character? -- --
-- > isExtSeparator a == (a == extSeparator) --isExtSeparator :: Char -> Bool -- | Rather than using (== pathSeparator), use this. Test -- if something is a path separator. -- --
-- > isPathSeparator a == (a `elem` pathSeparators) --isPathSeparator :: Char -> Bool -- | Is the character a file separator? -- --
-- > isSearchPathSeparator a == (a == searchPathSeparator) --isSearchPathSeparator :: Char -> Bool -- | This is a more flexible variant of addExtension / -- <.> which can work with files or directories -- --
-- > genericAddExtension "/" "x" == "/.x" --genericAddExtension :: Path ar fd -> String -> Path ar fd genericDropExtension :: Path ar fd -> Path ar fd genericDropExtensions :: Path ar fd -> Path ar fd genericSplitExtension :: Path ar fd -> (Path ar fd, String) genericSplitExtensions :: Path ar fd -> (Path ar fd, String) genericTakeExtension :: Path ar fd -> String genericTakeExtensions :: Path ar fd -> String instance GHC.Classes.Ord (System.Path.Posix.Path ar fd) instance GHC.Classes.Eq (System.Path.Posix.Path ar fd) instance GHC.Classes.Ord System.Path.Posix.PathComponent instance GHC.Classes.Eq System.Path.Posix.PathComponent instance GHC.Show.Show System.Path.Posix.PathComponent instance System.Path.Posix.Private System.Path.Posix.Abs instance System.Path.Posix.Private System.Path.Posix.Rel instance System.Path.Posix.Private System.Path.Posix.File instance System.Path.Posix.Private System.Path.Posix.Dir instance System.Path.Posix.AbsRelClass System.Path.Posix.Abs instance System.Path.Posix.AbsRelClass System.Path.Posix.Rel instance System.Path.Posix.FileDirClass System.Path.Posix.File instance System.Path.Posix.FileDirClass System.Path.Posix.Dir instance System.Path.Posix.AbsRelClass ar => GHC.Show.Show (System.Path.Posix.Path ar fd) instance System.Path.Posix.AbsRelClass ar => GHC.Read.Read (System.Path.Posix.Path ar fd) instance Data.String.IsString (System.Path.Posix.Path ar fd) instance Test.QuickCheck.Arbitrary.Arbitrary System.Path.Posix.PathComponent instance Test.QuickCheck.Arbitrary.Arbitrary (System.Path.Posix.Path ar System.Path.Posix.File) instance Test.QuickCheck.Arbitrary.Arbitrary (System.Path.Posix.Path ar System.Path.Posix.Dir) -- | This module provides type-safe access to filepath manipulations. -- -- It is designed to be imported instead of System.FilePath. (It -- is intended to provide versions of functions from that module which -- have equivalent functionality but are more typesafe). -- System.Path.Directory is a companion module providing a -- type-safe alternative to System.Directory. -- -- The heart of this module is the Path ar fd abstract -- type which represents file and directory paths. The idea is that there -- are two phantom type parameters - the first should be Abs or -- Rel, and the second File or Dir. A number of type -- synonyms are provided for common types: -- --
-- type AbsFile = Path Abs File -- type RelFile = Path Rel File -- type AbsDir = Path Abs Dir -- type RelDir = Path Rel Dir -- -- type AbsPath fd = Path Abs fd -- type RelPath fd = Path Rel fd -- type FilePath ar = Path ar File -- type DirPath ar = Path ar Dir ---- -- The type of the combine (aka </>) function gives -- the idea: -- --
-- (</>) :: DirPath ar -> RelPath fd -> Path ar fd ---- -- Together this enables us to give more meaningful types to a lot of the -- functions, and (hopefully) catch a bunch more errors at compile time. -- -- Overloaded string literals are supported, so with the -- OverloadedStrings extension enabled, you can: -- --
-- f :: FilePath ar -- f = "tmp" </> "someFile" <.> "ext" ---- -- If you don't want to use OverloadedStrings, you can use the -- construction fns: -- --
-- f :: FilePath ar -- f = asDirPath "tmp" </> asFilePath "someFile" <.> "ext" ---- -- or... -- --
-- f :: FilePath ar -- f = asPath "tmp" </> asPath "someFile" <.> "ext" ---- -- or just... -- --
-- f :: FilePath ar -- f = asPath "tmp/someFile.ext" ---- -- One point to note is that whether one of these is interpreted as an -- absolute or a relative path depends on the type at which it is used: -- --
-- *System.Path> f :: AbsFile -- /tmp/someFile.ext -- *System.Path> f :: RelFile -- tmp/someFile.ext ---- -- You will typically want to import as follows: -- --
-- import Prelude hiding (FilePath) -- import System.Path -- import System.Path.Directory -- import System.Path.IO ---- -- The basic API (and properties satisfied) are heavily influenced by -- Neil Mitchell's System.FilePath module. -- -- Ben Moseley - (c) 2009-2010 module System.Path -- | This module provides type-safe access to directory manipulations. -- -- It is designed to be imported instead of System.Directory. (It -- is intended to provide versions of functions from that module which -- have equivalent functionality but are more typesafe). -- System.Path is a companion module providing a type-safe -- alternative to System.FilePath. -- -- You will typically want to import as follows: -- --
-- import Prelude hiding (FilePath) -- import System.Path -- import System.Path.Directory -- import System.Path.IO ---- -- Ben Moseley - (c) 2009 module System.Path.Directory createDirectory :: AbsRelClass ar => DirPath ar -> IO () createDirectoryIfMissing :: AbsRelClass ar => Bool -> DirPath ar -> IO () removeDirectory :: AbsRelClass ar => DirPath ar -> IO () removeDirectoryRecursive :: AbsRelClass ar => DirPath ar -> IO () renameDirectory :: (AbsRelClass ar1, AbsRelClass ar2) => DirPath ar1 -> DirPath ar2 -> IO () -- | An alias for relDirectoryContents. getDirectoryContents :: AbsRelClass ar => DirPath ar -> IO ([RelDir], [RelFile]) -- | Retrieve the contents of a directory path (which may be relative) as -- absolute paths absDirectoryContents :: AbsRelClass ar => DirPath ar -> IO ([AbsDir], [AbsFile]) -- | Returns paths relative to the supplied (abs or relative) -- directory path. eg (for current working directory of -- /somewhere/cwd/): -- --
-- show (relDirectoryContents "d/e/f/") == (["subDir1A","subDir1B"], -- ["file1A","file1B"]) --relDirectoryContents :: AbsRelClass ar => DirPath ar -> IO ([RelDir], [RelFile]) -- | A convenient alternative to relDirectoryContents if you only -- want files. filesInDir :: AbsRelClass ar => DirPath ar -> IO [RelFile] -- | A convenient alternative to relDirectoryContents if you only -- want directories. dirsInDir :: AbsRelClass ar => DirPath ar -> IO [RelDir] getCurrentDirectory :: IO AbsDir setCurrentDirectory :: AbsRelClass ar => DirPath ar -> IO () getHomeDirectory :: IO AbsDir getAppUserDataDirectory :: String -> IO AbsDir getUserDocumentsDirectory :: IO AbsDir getTemporaryDirectory :: IO AbsDir removeFile :: AbsRelClass ar => FilePath ar -> IO () renameFile :: (AbsRelClass ar1, AbsRelClass ar2) => FilePath ar1 -> FilePath ar2 -> IO () copyFile :: (AbsRelClass ar1, AbsRelClass ar2) => FilePath ar1 -> FilePath ar2 -> IO () canonicalizePath :: AbsRelClass ar => Path ar fd -> IO (AbsPath fd) makeRelativeToCurrentDirectory :: AbsRelClass ar => Path ar fd -> IO (RelPath fd) findExecutable :: String -> IO (Maybe AbsFile) doesFileExist :: AbsRelClass ar => FilePath ar -> IO Bool doesDirectoryExist :: AbsRelClass ar => DirPath ar -> IO Bool data Permissions :: * getPermissions :: AbsRelClass ar => Path ar fd -> IO Permissions setPermissions :: AbsRelClass ar => Path ar fd -> Permissions -> IO () getModificationTime :: AbsRelClass ar => Path ar fd -> IO UTCTime -- | This module provides type-safe access to IO operations. -- -- It is designed to be imported instead of System.IO. (It is -- intended to provide versions of functions from that module which have -- equivalent functionality but are more typesafe). System.Path is -- a companion module providing a type-safe alternative to -- System.FilePath. -- -- You will typically want to import as follows: -- --
-- import Prelude hiding (FilePath) -- import System.Path -- import System.Path.Directory -- import System.Path.IO ---- -- Ben Moseley - (c) 2009 module System.Path.IO withFile :: AbsRelClass ar => Path ar fd -> IOMode -> (Handle -> IO r) -> IO r openFile :: AbsRelClass ar => FilePath ar -> IOMode -> IO Handle readFile :: AbsRelClass ar => FilePath ar -> IO String writeFile :: AbsRelClass ar => FilePath ar -> String -> IO () appendFile :: AbsRelClass ar => FilePath ar -> String -> IO () withBinaryFile :: AbsRelClass ar => FilePath ar -> IOMode -> (Handle -> IO r) -> IO r openBinaryFile :: AbsRelClass ar => FilePath ar -> IOMode -> IO Handle openTempFile :: AbsRelClass ar => DirPath ar -> RelFile -> IO (AbsFile, Handle) openBinaryTempFile :: AbsRelClass ar => DirPath ar -> RelFile -> IO (AbsFile, Handle) -- | A value of type IO a is a computation which, when -- performed, does some I/O before returning a value of type a. -- -- There is really only one way to "perform" an I/O action: bind it to -- Main.main in your program. When your program is run, the I/O -- will be performed. It isn't possible to perform I/O from an arbitrary -- function, unless that function is itself in the IO monad and -- called at some point, directly or indirectly, from Main.main. -- -- IO is a monad, so IO actions can be combined using -- either the do-notation or the >> and >>= -- operations from the Monad class. data IO a :: * -> * fixIO :: (a -> IO a) -> IO a -- | Haskell defines operations to read and write characters from and to -- files, represented by values of type Handle. Each value of -- this type is a handle: a record used by the Haskell run-time -- system to manage I/O with file system objects. A handle has at -- least the following properties: -- --
-- main = print ([(n, 2^n) | n <- [0..19]]) --print :: Show a => a -> IO () -- | Read a character from the standard input device (same as -- hGetChar stdin). getChar :: IO Char -- | Read a line from the standard input device (same as hGetLine -- stdin). getLine :: IO String -- | The getContents operation returns all user input as a single -- string, which is read lazily as it is needed (same as -- hGetContents stdin). getContents :: IO String -- | The readIO function is similar to read except that it -- signals parse failure to the IO monad instead of terminating -- the program. readIO :: Read a => String -> IO a -- | The readLn function combines getLine and readIO. readLn :: Read a => IO a -- | Select binary mode (True) or text mode (False) on a open -- handle. (See also openBinaryFile.) -- -- This has the same effect as calling hSetEncoding with -- char8, together with hSetNewlineMode with -- noNewlineTranslation. hSetBinaryMode :: Handle -> Bool -> IO () -- | hPutBuf hdl buf count writes count 8-bit -- bytes from the buffer buf to the handle hdl. It -- returns (). -- -- hPutBuf ignores any text encoding that applies to the -- Handle, writing the bytes directly to the underlying file or -- device. -- -- hPutBuf ignores the prevailing TextEncoding and -- NewlineMode on the Handle, and writes bytes directly. -- -- This operation may fail with: -- --