-- 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 package is the Path ar fd abstract -- type which represents file and directory paths. The idea is that there -- are two 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 Path.AbsFile = Path Abs File -- type Path.RelFile = Path Rel File -- type Path.AbsDir = Path Abs Dir -- type Path.RelDir = Path Rel Dir -- -- type Path.Abs fd = Path Abs fd -- type Path.Rel fd = Path Rel fd -- type Path.File ar = Path ar File -- type Path.Dir ar = Path ar Dir ---- -- The type of the combine (aka </>) function gives -- the idea: -- --
-- (</>) :: Path.Dir ar -> Path.Rel 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. -- -- For more details see the README.md file. -- -- Related packages: -- --
-- Path.pathMap (map toLower) (absDir "/tmp/Reports/SpreadSheets") == Posix.absDir "/tmp/reports/spreadsheets" --pathMap :: FileDir fd => (String -> String) -> Path os ar fd -> Path os ar fd withAbsRel :: AbsRel ar => (AbsPath os fd -> a) -> (RelPath os fd -> a) -> Path os ar fd -> a withFileDir :: FileOrDir fd => (FilePath os ar -> a) -> (DirPath os ar -> a) -> Path os ar fd -> a -- | Convert the Path into a plain String as required for OS -- calls. -- --
-- \p -> Path.asPath (Path.toString p) == (p::Default.AbsFile) --toString :: (System os, AbsRel ar, FileDir fd) => Path os ar fd -> String -- | Synonym of toString intended for unqualified use. -- | Deprecated: Use Path.toString instead. getPathString :: (System os, AbsRel ar, FileDir fd) => Path os ar fd -> String rootDir :: System os => AbsDir os currentDir :: System os => RelDir os -- | This is a file with path "". You will not be able to create a -- file with this name. We also forbid parsing "" by -- relFile. You might only need this file path as intermediate -- step when manipulating extensions of files like ".bashrc". emptyFile :: System os => RelFile os -- | This function is intended for checking and parsing paths provided as -- user input. -- --
-- fmap Posix.toString (Posix.maybePath "/" :: Maybe Posix.AbsDir) == Just "/" ---- --
-- fmap Posix.toString (Posix.maybePath "/" :: Maybe Posix.AbsFile) == Nothing ---- --
-- fmap Posix.toString (Posix.maybePath "/" :: Maybe Posix.RelDir) == Nothing ---- --
-- fmap Posix.toString (Posix.maybePath "/" :: Maybe Posix.RelFile) == Nothing ---- --
-- fmap Posix.toString (Posix.maybePath "/tmp" :: Maybe Posix.AbsDir) == Just "/tmp" ---- --
-- fmap Posix.toString (Posix.maybePath "/tmp" :: Maybe Posix.AbsFile) == Just "/tmp" ---- --
-- fmap Posix.toString (Posix.maybePath "/tmp" :: Maybe Posix.RelDir) == Nothing ---- --
-- fmap Posix.toString (Posix.maybePath "/tmp" :: Maybe Posix.RelFile) == Nothing ---- --
-- fmap Posix.toString (Posix.maybePath "/tmp/" :: Maybe Posix.AbsDir) == Just "/tmp" ---- --
-- fmap Posix.toString (Posix.maybePath "/tmp/" :: Maybe Posix.AbsFile) == Nothing ---- --
-- fmap Posix.toString (Posix.maybePath "/tmp/" :: Maybe Posix.RelDir) == Nothing ---- --
-- fmap Posix.toString (Posix.maybePath "/tmp/" :: Maybe Posix.RelFile) == Nothing ---- --
-- fmap Posix.toString (Posix.maybePath "/tmp" :: Maybe Posix.AbsRelFileDir) == Just "/tmp" ---- --
-- fmap Posix.toString (Posix.maybePath "/tmp/" :: Maybe Posix.AbsRelFileDir) == Just "/tmp" ---- --
-- fmap Posix.toString (Posix.maybePath "file.txt" :: Maybe Posix.RelFile) == Just "file.txt" ---- --
-- fmap Posix.toString (Posix.maybePath "file.txt" :: Maybe Posix.AbsFile) == Nothing ---- --
-- fmap Windows.toString (Windows.maybePath "\\tmp" :: Maybe Windows.AbsDir) == Just "\\tmp" ---- --
-- fmap Windows.toString (Windows.maybePath "a:\\tmp" :: Maybe Windows.AbsDir) == Just "a:\\tmp" ---- --
-- fmap Windows.toString (Windows.maybePath "a:tmp" :: Maybe Windows.AbsDir) == Just "a:tmp" ---- --
-- fmap Windows.toString (Windows.maybePath "a:\\" :: Maybe Windows.AbsDir) == Just "a:\\" ---- --
-- fmap Windows.toString (Windows.maybePath "a:" :: Maybe Windows.AbsDir) == Just "a:" ---- --
-- fmap Windows.toString (Windows.maybePath "tmp" :: Maybe Windows.RelDir) == Just "tmp" ---- --
-- fmap Windows.toString (Windows.maybePath "\\tmp" :: Maybe Windows.RelDir) == Nothing ---- --
-- fmap Windows.toString (Windows.maybePath "a:\\tmp" :: Maybe Windows.RelDir) == Nothing ---- --
-- fmap Windows.toString (Windows.maybePath "a:tmp" :: Maybe Windows.RelDir) == Nothing ---- --
-- fmap Windows.toString (Windows.maybePath "tmp" :: Maybe Windows.AbsDir) == Nothing --maybe :: (System os, AbsRel ar, FileDir fd) => String -> Maybe (Path os ar fd) -- | This function is intended for checking and parsing paths provided as -- user input. -- --
-- fmap Posix.toString (Posix.maybePath "/" :: Maybe Posix.AbsDir) == Just "/" ---- --
-- fmap Posix.toString (Posix.maybePath "/" :: Maybe Posix.AbsFile) == Nothing ---- --
-- fmap Posix.toString (Posix.maybePath "/" :: Maybe Posix.RelDir) == Nothing ---- --
-- fmap Posix.toString (Posix.maybePath "/" :: Maybe Posix.RelFile) == Nothing ---- --
-- fmap Posix.toString (Posix.maybePath "/tmp" :: Maybe Posix.AbsDir) == Just "/tmp" ---- --
-- fmap Posix.toString (Posix.maybePath "/tmp" :: Maybe Posix.AbsFile) == Just "/tmp" ---- --
-- fmap Posix.toString (Posix.maybePath "/tmp" :: Maybe Posix.RelDir) == Nothing ---- --
-- fmap Posix.toString (Posix.maybePath "/tmp" :: Maybe Posix.RelFile) == Nothing ---- --
-- fmap Posix.toString (Posix.maybePath "/tmp/" :: Maybe Posix.AbsDir) == Just "/tmp" ---- --
-- fmap Posix.toString (Posix.maybePath "/tmp/" :: Maybe Posix.AbsFile) == Nothing ---- --
-- fmap Posix.toString (Posix.maybePath "/tmp/" :: Maybe Posix.RelDir) == Nothing ---- --
-- fmap Posix.toString (Posix.maybePath "/tmp/" :: Maybe Posix.RelFile) == Nothing ---- --
-- fmap Posix.toString (Posix.maybePath "/tmp" :: Maybe Posix.AbsRelFileDir) == Just "/tmp" ---- --
-- fmap Posix.toString (Posix.maybePath "/tmp/" :: Maybe Posix.AbsRelFileDir) == Just "/tmp" ---- --
-- fmap Posix.toString (Posix.maybePath "file.txt" :: Maybe Posix.RelFile) == Just "file.txt" ---- --
-- fmap Posix.toString (Posix.maybePath "file.txt" :: Maybe Posix.AbsFile) == Nothing ---- --
-- fmap Windows.toString (Windows.maybePath "\\tmp" :: Maybe Windows.AbsDir) == Just "\\tmp" ---- --
-- fmap Windows.toString (Windows.maybePath "a:\\tmp" :: Maybe Windows.AbsDir) == Just "a:\\tmp" ---- --
-- fmap Windows.toString (Windows.maybePath "a:tmp" :: Maybe Windows.AbsDir) == Just "a:tmp" ---- --
-- fmap Windows.toString (Windows.maybePath "a:\\" :: Maybe Windows.AbsDir) == Just "a:\\" ---- --
-- fmap Windows.toString (Windows.maybePath "a:" :: Maybe Windows.AbsDir) == Just "a:" ---- --
-- fmap Windows.toString (Windows.maybePath "tmp" :: Maybe Windows.RelDir) == Just "tmp" ---- --
-- fmap Windows.toString (Windows.maybePath "\\tmp" :: Maybe Windows.RelDir) == Nothing ---- --
-- fmap Windows.toString (Windows.maybePath "a:\\tmp" :: Maybe Windows.RelDir) == Nothing ---- --
-- fmap Windows.toString (Windows.maybePath "a:tmp" :: Maybe Windows.RelDir) == Nothing ---- --
-- fmap Windows.toString (Windows.maybePath "tmp" :: Maybe Windows.AbsDir) == Nothing ---- | Deprecated: Use Path.maybe instead. maybePath :: (System os, AbsRel ar, FileDir fd) => String -> Maybe (Path os ar fd) parse :: (System os, AbsRel ar, FileDir fd) => String -> Either String (Path os ar fd) -- | Deprecated: Use Path.parse instead. parsePath :: (System os, AbsRel ar, FileDir fd) => String -> Either String (Path os ar fd) -- | This function is intended for converting path strings with known -- content, e.g. string literals, to the Path type. path :: (System os, AbsRel ar, FileDir fd) => String -> Path os ar fd -- | Construct a RelFile from a String. -- --
-- Posix.toString (Posix.relFile "file.txt") == "file.txt" ---- --
-- Posix.toString (Posix.relFile "tmp") == "tmp" --relFile :: System os => String -> RelFile os -- | Construct a RelDir from a String. -- --
-- Posix.toString (Posix.relDir ".") == "." ---- --
-- Posix.toString (Posix.relDir "file.txt") == "file.txt" ---- --
-- Posix.toString (Posix.relDir "tmp") == "tmp" --relDir :: System os => String -> RelDir os -- | Construct an AbsFile from a String. -- --
-- Posix.toString (Posix.absFile "/file.txt") == "/file.txt" ---- --
-- Posix.toString (Posix.absFile "/tmp") == "/tmp" --absFile :: System os => String -> AbsFile os -- | Construct an AbsDir from a String. -- --
-- Posix.toString (Posix.absDir "/file.txt") == "/file.txt" ---- --
-- Posix.toString (Posix.absDir "/tmp") == "/tmp" --absDir :: System os => String -> AbsDir os -- | Construct a 'Rel fd' from a String. rel :: (System os, FileDir fd) => String -> Rel os fd -- | Construct an 'Abs fd' from a String. abs :: (System os, FileDir fd) => String -> Abs os fd -- | Construct an 'AbsRel fd' from a String. absRel :: (System os, FileDir fd) => String -> AbsRel os fd -- | Construct a 'File ar' from a String. file :: (System os, AbsRel ar) => String -> File os ar -- | Construct a 'Dir ar' from a String. dir :: (System os, AbsRel ar) => String -> Dir os ar -- | Construct a 'FileDir ar' from a String. fileDir :: (System os, AbsRel ar) => String -> FileDir os ar -- | Construct a 'RelPath fd' from a String. -- | Deprecated: Use Path.rel instead. relPath :: (System os, FileDir fd) => String -> RelPath os fd -- | Construct an 'AbsPath fd' from a String. -- | Deprecated: Use Path.abs instead. absPath :: (System os, FileDir fd) => String -> AbsPath os fd -- | Construct a 'FilePath ar' from a String. -- | Deprecated: Use Path.file instead. filePath :: (System os, AbsRel ar) => String -> FilePath os ar -- | Construct a 'DirPath ar' from a String. -- | Deprecated: Use Path.dir instead. dirPath :: (System os, AbsRel ar) => String -> DirPath os ar idAbsRel :: AbsRelPath os fd -> AbsRelPath os fd idAbs :: AbsPath os fd -> AbsPath os fd idRel :: RelPath os fd -> RelPath os fd idFileDir :: FileDirPath os fd -> FileDirPath os fd idFile :: FilePath os fd -> FilePath os fd idDir :: DirPath os fd -> DirPath os fd -- | Use a String as a Path whose type is determined by its -- context. You should not use this and other as* functions, -- since they may silently turn a relative path to an absolute one, or -- vice versa, or they may accept a path as file path although it ends on -- a slash. If you are certain about the string content then you should -- use path. If you got the string as user input then use -- maybePath or parsePath. -- --
-- Posix.asPath "/tmp" == Posix.absDir "/tmp" ---- --
-- Posix.asPath "file.txt" == Posix.relFile "file.txt" ---- --
-- Path.isAbsolute (Posix.asAbsDir "/tmp") ---- --
-- Path.isRelative (Posix.asRelDir "/tmp") ---- --
-- Posix.toString (Posix.asPath "/tmp" :: Posix.AbsDir) == "/tmp" ---- --
-- Posix.toString (Posix.asPath "/tmp" :: Posix.RelDir) == "tmp" ---- --
-- Windows.toString (Windows.asPath "\\tmp" :: Windows.AbsDir) == "\\tmp" ---- --
-- Windows.toString (Windows.asPath "a:\\tmp" :: Windows.AbsDir) == "a:\\tmp" ---- --
-- Windows.toString (Windows.asPath "a:tmp" :: Windows.AbsDir) == "a:tmp" ---- --
-- Windows.toString (Windows.asPath "tmp" :: Windows.RelDir) == "tmp" ---- | Deprecated: Use maybePath, parsePath or path -- instead. asPath :: (System os, AbsRel ar, FileDir fd) => String -> Path os ar fd -- | Use a String as a RelFile. No checking is done. -- --
-- Posix.toString (Posix.asRelFile "file.txt") == "file.txt" ---- --
-- Posix.toString (Posix.asRelFile "/file.txt") == "file.txt" ---- --
-- Posix.toString (Posix.asRelFile "tmp") == "tmp" ---- --
-- Posix.toString (Posix.asRelFile "/tmp") == "tmp" ---- | Deprecated: Use relFile instead. asRelFile :: System os => String -> RelFile os -- | Use a String as a RelDir. No checking is done. -- --
-- Posix.toString (Posix.asRelDir ".") == "." ---- --
-- Posix.toString (Posix.asRelDir "file.txt") == "file.txt" ---- --
-- Posix.toString (Posix.asRelDir "/file.txt") == "file.txt" ---- --
-- Posix.toString (Posix.asRelDir "tmp") == "tmp" ---- --
-- Posix.toString (Posix.asRelDir "/tmp") == "tmp" ---- | Deprecated: Use relDir instead. asRelDir :: System os => String -> RelDir os -- | Use a String as an AbsFile. No checking is done. -- --
-- Posix.toString (Posix.asAbsFile "/file.txt") == "/file.txt" ---- --
-- Posix.toString (Posix.asAbsFile "/tmp") == "/tmp" ---- | Deprecated: Use absFile instead. asAbsFile :: System os => String -> AbsFile os -- | Use a String as an AbsDir. No checking is done. -- --
-- Posix.toString (Posix.asAbsDir "/file.txt") == "/file.txt" ---- --
-- Posix.toString (Posix.asAbsDir "/tmp") == "/tmp" ---- | Deprecated: Use absDir instead. asAbsDir :: System os => String -> AbsDir os -- | Use a String as a 'RelPath fd'. No checking is done. -- | Deprecated: Use relPath instead. asRelPath :: (System os, FileDir fd) => String -> RelPath os fd -- | Use a String as an 'AbsPath fd'. No checking is done. -- | Deprecated: Use absPath instead. asAbsPath :: (System os, FileDir fd) => String -> AbsPath os fd -- | Use a String as a 'FilePath ar'. No checking is done. -- | Deprecated: Use filePath instead. asFilePath :: (System os, AbsRel ar) => String -> FilePath os ar -- | Use a String as a 'DirPath ar'. No checking is done. -- | Deprecated: Use dirPath instead. asDirPath :: (System os, AbsRel ar) => String -> DirPath os ar -- | Examines the supplied string and constructs an absolute or relative -- path as appropriate. -- --
-- Path.mkPathAbsOrRel "/tmp" == Left (Posix.absDir "/tmp") ---- --
-- Path.mkPathAbsOrRel "tmp" == Right (Posix.relDir "tmp") ---- --
-- Path.mkPathAbsOrRel "\\tmp" == Left (Windows.absDir "\\tmp") ---- --
-- Path.mkPathAbsOrRel "d:\\tmp" == Left (Windows.absDir "d:\\tmp") ---- --
-- Path.mkPathAbsOrRel "d:tmp" == Left (Windows.absDir "d:tmp") ---- --
-- Path.mkPathAbsOrRel "tmp" == Right (Windows.relDir "tmp") ---- | Deprecated: Use Path.absRel instead. mkPathAbsOrRel :: (System os, FileDir fd) => String -> Either (AbsPath os fd) (RelPath os 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. -- | Deprecated: Don't let the path type depend on current file system -- content. Instead choose the path type according to the needed disk -- object type. mkPathFileOrDir :: (System os, AbsRel ar) => String -> IO (Maybe (Either (FilePath os ar) (DirPath os ar))) -- | Convert a String into an AbsPath by interpreting it as -- relative to the supplied directory if necessary. -- --
-- Path.mkAbsPath (absDir "/tmp") "foo.txt" == Posix.absFile "/tmp/foo.txt" ---- --
-- Path.mkAbsPath (absDir "/tmp") "/etc/foo.txt" == Posix.absFile "/etc/foo.txt" ---- | Deprecated: Use Path.dynamicMakeAbsolute instead. mkAbsPath :: (System os, FileDir fd) => AbsDir os -> String -> AbsPath os fd -- | Convert a String into an AbsPath by interpreting it as -- relative to the cwd if necessary. -- | Deprecated: Use Path.dynamicMakeAbsoluteFromCwd instead. mkAbsPathFromCwd :: (System os, FileDir fd) => String -> IO (AbsPath os fd) -- | Infix variant of combine. -- --
-- Posix.toString (Posix.absDir "/tmp" </> Posix.relFile "file.txt") == "/tmp/file.txt" ---- --
-- Posix.toString (Posix.absDir "/tmp" </> Posix.relDir "dir" </> Posix.relFile "file.txt") == "/tmp/dir/file.txt" ---- --
-- Posix.toString (Posix.relDir "dir" </> Posix.relFile "file.txt") == "dir/file.txt" ---- --
-- Windows.toString (Windows.absDir "\\tmp" </> Windows.relFile "file.txt") == "\\tmp\\file.txt" ---- --
-- Windows.toString (Windows.absDir "c:\\tmp" </> Windows.relFile "file.txt") == "c:\\tmp\\file.txt" ---- --
-- Windows.toString (Windows.absDir "c:tmp" </> Windows.relFile "file.txt") == "c:tmp\\file.txt" ---- --
-- Windows.toString (Windows.absDir "c:\\" </> Windows.relDir "tmp" </> Windows.relFile "file.txt") == "c:\\tmp\\file.txt" ---- --
-- Windows.toString (Windows.absDir "c:" </> Windows.relDir "tmp" </> Windows.relFile "file.txt") == "c:tmp\\file.txt" ---- --
-- Windows.toString (Windows.relDir "dir" </> Windows.relFile "file.txt") == "dir\\file.txt" --(>) :: DirPath os ar -> RelPath os fd -> Path os ar fd infixr 5 > -- | Infix variant of addExtension. 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 os ar -> String -> FilePath os ar infixl 7 <.> (<++>) :: FilePath os ar -> String -> FilePath os ar infixl 7 <++> -- | Add an extension, even if there is already one there. E.g. -- addExtension "foo.txt" "bat" -> "foo.txt.bat". -- --
-- Path.addExtension (relFile "file.txt") "bib" == Posix.relFile "file.txt.bib" ---- --
-- Path.addExtension (relFile "file.") ".bib" == Posix.relFile "file..bib" ---- --
-- Path.addExtension (relFile "file") ".bib" == Posix.relFile "file.bib" ---- --
-- Path.addExtension Path.emptyFile "bib" == Posix.relFile ".bib" ---- --
-- Path.addExtension Path.emptyFile ".bib" == Posix.relFile ".bib" ---- --
-- Path.takeFileName (Path.addExtension Path.emptyFile "ext") == Posix.relFile ".ext" --addExtension :: FilePath os ar -> String -> FilePath os ar -- | Join an (absolute or relative) directory path with a relative (file or -- directory) path to form a new path. -- --
-- \p -> Path.combine Path.currentDir p == (p::Default.RelDir) --combine :: DirPath os ar -> RelPath os fd -> Path os ar fd -- | Remove last extension, and the "." preceding it. -- --
-- forAllAbsRel $ \x -> Path.dropExtension x == fst (Path.splitExtension x) --dropExtension :: FilePath os ar -> FilePath os ar -- | Drop all extensions -- --
-- forAllAbsRel $ \x -> not $ Path.hasAnExtension (Path.dropExtensions x) --dropExtensions :: FilePath os ar -> FilePath os ar -- | Synonym for takeDirectory dropFileName :: FilePath os ar -> DirPath os ar -- | Set the extension of a file, overwriting one if already present. -- --
-- Path.replaceExtension (relFile "file.txt") ".bob" == Posix.relFile "file.bob" ---- --
-- Path.replaceExtension (relFile "file.txt") "bob" == Posix.relFile "file.bob" ---- --
-- Path.replaceExtension (relFile "file") ".bob" == Posix.relFile "file.bob" ---- --
-- Path.replaceExtension (relFile "file.txt") "" == Posix.relFile "file" ---- --
-- Path.replaceExtension (relFile "file.fred.bob") "txt" == Posix.relFile "file.fred.txt" --replaceExtension :: FilePath os ar -> String -> FilePath os ar replaceBaseName :: FilePath os ar -> String -> FilePath os ar replaceDirectory :: FilePath os ar1 -> DirPath os ar2 -> FilePath os ar2 replaceFileName :: FilePath os ar -> String -> FilePath os ar -- | Split on the extension. addExtension is the inverse. -- --
-- forAllAbsRel $ \x -> uncurry (<.>) (Path.splitExtension x) == x ---- --
-- forAllAbsRel $ \x -> uncurry Path.addExtension (Path.splitExtension x) == x ---- --
-- Path.splitExtension (relFile "file.txt") == (Posix.relFile "file",".txt") ---- --
-- Path.splitExtension (relFile ".bashrc") == (Posix.emptyFile, ".bashrc") ---- --
-- Path.splitExtension (relFile "file") == (Posix.relFile "file","") ---- --
-- Path.splitExtension (relFile "file/file.txt") == (Posix.relFile "file/file",".txt") ---- --
-- Path.splitExtension (relFile "file.txt/boris") == (Posix.relFile "file.txt/boris","") ---- --
-- Path.splitExtension (relFile "file.txt/boris.ext") == (Posix.relFile "file.txt/boris",".ext") ---- --
-- Path.splitExtension (relFile "file/path.txt.bob.fred") == (Posix.relFile "file/path.txt.bob",".fred") --splitExtension :: FilePath os ar -> (FilePath os ar, String) -- | Split on all extensions -- --
-- Path.splitExtensions (relFile "file.tar.gz") == (Posix.relFile "file",".tar.gz") ---- --
-- \p -> uncurry (<.>) (Path.splitExtension p) == (p::Default.AbsFile) --splitExtensions :: FilePath os ar -> (FilePath os ar, String) -- |
-- \p -> uncurry Path.combine (Path.splitFileName p) == (p::Default.AbsFile) --splitFileName :: FilePath os ar -> (DirPath os ar, RelFile os) -- |
-- \p -> (uncurry Path.combine <$> Path.splitDirName p) == toMaybe (not $ Default.isDrive p) (p::Default.AbsDir) --splitDirName :: DirPath os ar -> Maybe (DirPath os ar, RelDir os) -- | Get the basename of a file -- --
-- Path.takeBaseName (absFile "/tmp/somedir/myfile.txt") == Posix.relFile "myfile" ---- --
-- Path.takeBaseName (relFile "./myfile.txt") == Posix.relFile "myfile" ---- --
-- Path.takeBaseName (relFile "myfile.txt") == Posix.relFile "myfile" --takeBaseName :: FilePath os ar -> RelFile os takeDirectory :: FilePath os ar -> DirPath os ar takeSuperDirectory :: DirPath os ar -> Maybe (DirPath os ar) -- | Get the extension of a file, returns "" for no extension, -- .ext otherwise. -- --
-- forAllAbsRel $ \x -> Path.takeExtension x == snd (Path.splitExtension x) ---- --
-- forAllAbsRel $ \x -> Path.takeExtension (Path.addExtension x "ext") == ".ext" ---- --
-- forAllAbsRel $ \x -> Path.takeExtension (Path.replaceExtension x "ext") == ".ext" --takeExtension :: FilePath os ar -> String -- | Get all extensions -- --
-- Path.takeExtensions (Posix.relFile "file.tar.gz") == ".tar.gz" --takeExtensions :: FilePath os ar -> String -- | Get the filename component of a file path (ie stripping all parent -- dirs) -- --
-- Path.takeFileName (absFile "/tmp/somedir/myfile.txt") == Posix.relFile "myfile.txt" ---- --
-- Path.takeFileName (relFile "./myfile.txt") == Posix.relFile "myfile.txt" ---- --
-- Path.takeFileName (relFile "myfile.txt") == Posix.relFile "myfile.txt" ---- --
-- \p -> Path.toString (Path.takeFileName p) `isSuffixOf` Path.toString (p::Default.AbsFile) --takeFileName :: FilePath os ar -> RelFile os -- |
-- \p -> fmap (\d -> toString d `isSuffixOf` toString p) (takeDirName p) == toMaybe (not $ isDrive p) True --takeDirName :: DirPath os ar -> Maybe (RelDir os) mapFileName :: (String -> String) -> FilePath os ar -> FilePath os ar mapFileNameF :: Functor f => (String -> f String) -> FilePath os ar -> f (FilePath os ar) -- | Check whether two strings are equal as file paths. -- --
-- Posix.equalFilePath "abc/def" "abc/def" ---- --
-- Posix.equalFilePath "abc/def" "abc//def" ---- --
-- Posix.equalFilePath "/tmp/" "/tmp" ---- --
-- Posix.equalFilePath "/tmp" "//tmp" ---- --
-- Posix.equalFilePath "/tmp" "///tmp" ---- --
-- not $ Posix.equalFilePath "abc" "def" ---- --
-- not $ Posix.equalFilePath "/tmp" "tmp" ---- --
-- Windows.equalFilePath "abc\\def" "abc\\def" ---- --
-- Windows.equalFilePath "abc\\def" "abc\\\\def" ---- --
-- Windows.equalFilePath "file" "File" ---- --
-- Windows.equalFilePath "\\file" "\\\\file" ---- --
-- Windows.equalFilePath "\\file" "\\\\\\file" ---- --
-- not $ Windows.equalFilePath "abc" "def" ---- --
-- not $ Windows.equalFilePath "file" "dir" --equalFilePath :: System os => Tagged os (String -> String -> Bool) -- | Constructs a RelPath from a list of components. It is an -- unchecked error if the path components contain path separators. It is -- an unchecked error if a RelFile path is empty. -- --
-- Path.joinPath ["tmp","someDir","dir"] == Posix.relDir "tmp/someDir/dir" ---- --
-- Path.joinPath ["tmp","someDir","file.txt"] == Posix.relFile "tmp/someDir/file.txt" --joinPath :: FileDir fd => [String] -> RelPath os fd -- | Currently just transforms: -- --
-- Path.normalise (absFile "/tmp/fred/./jim/./file") == Posix.absFile "/tmp/fred/jim/file" --normalise :: System os => Path os ar fd -> Path os ar fd -- | Deconstructs a path into its components. -- --
-- Path.splitPath (Posix.absDir "/tmp/someDir/mydir.dir") == (True, map relDir ["tmp","someDir","mydir.dir"], Nothing) ---- --
-- Path.splitPath (Posix.absFile "/tmp/someDir/myfile.txt") == (True, map relDir ["tmp","someDir"], Just $ relFile "myfile.txt") --splitPath :: (AbsRel ar, FileOrDir fd) => Path os ar fd -> (Bool, [RelDir os], Maybe (RelFile os)) -- | 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. -- --
-- Path.makeRelative (absDir "/tmp/somedir") (absFile "/tmp/somedir/anotherdir/file.txt") == Posix.relFile "anotherdir/file.txt" ---- --
-- Path.makeRelative (absDir "/tmp/somedir") (absDir "/tmp/somedir/anotherdir/dir") == Posix.relDir "anotherdir/dir" ---- --
-- Path.makeRelative (absDir "c:\\tmp\\somedir") (absFile "C:\\Tmp\\SomeDir\\AnotherDir\\File.txt") == Windows.relFile "AnotherDir\\File.txt" ---- --
-- Path.makeRelative (absDir "c:\\tmp\\somedir") (absDir "c:\\tmp\\somedir\\anotherdir\\dir") == Windows.relDir "anotherdir\\dir" ---- --
-- Path.makeRelative (absDir "c:tmp\\somedir") (absDir "c:tmp\\somedir\\anotherdir\\dir") == Windows.relDir "anotherdir\\dir" --makeRelative :: (System os, FileDir fd) => AbsDir os -> AbsPath os fd -> RelPath os fd makeRelativeMaybe :: (System os, FileDir fd) => AbsDir os -> AbsPath os fd -> Maybe (RelPath os fd) -- | Joins an absolute directory with a relative path to construct a new -- absolute path. -- --
-- Path.makeAbsolute (absDir "/tmp") (relFile "file.txt") == Posix.absFile "/tmp/file.txt" ---- --
-- Path.makeAbsolute (absDir "/tmp") (relFile "adir/file.txt") == Posix.absFile "/tmp/adir/file.txt" ---- --
-- Path.makeAbsolute (absDir "/tmp") (relDir "adir/dir") == Posix.absDir "/tmp/adir/dir" ---- --
-- \base p -> Default.toString p `isSuffixOf` Path.toString (Path.makeAbsolute base (Path.idFile p)) ---- --
-- \base p -> Default.toString base `isPrefixOf` Path.toString (Path.makeAbsolute base (Path.idFile p)) --makeAbsolute :: System os => AbsDir os -> RelPath os fd -> AbsPath os fd -- | Converts a relative path into an absolute one by prepending the -- current working directory. makeAbsoluteFromCwd :: System os => RelPath os fd -> IO (AbsPath os fd) dynamicMakeAbsolute :: System os => AbsDir os -> AbsRelPath os fd -> AbsPath os fd dynamicMakeAbsoluteFromCwd :: System os => AbsRelPath os fd -> IO (AbsPath os fd) -- | As for makeAbsolute, but for use when the path may already be -- absolute (in which case it is left unchanged). You should avoid the -- use of genericMakeAbsolute-type functions, because then you -- avoid to absolutize a path that was already absolutized. -- --
-- Path.genericMakeAbsolute (absDir "/tmp") (relFile "file.txt") == Posix.absFile "/tmp/file.txt" ---- --
-- Path.genericMakeAbsolute (absDir "/tmp") (relFile "adir/file.txt") == Posix.absFile "/tmp/adir/file.txt" ---- --
-- Path.genericMakeAbsolute (absDir "/tmp") (absFile "/adir/file.txt") == Posix.absFile "/adir/file.txt" --genericMakeAbsolute :: (System os, AbsRel ar) => AbsDir os -> Path os ar fd -> AbsPath os fd -- | As for makeAbsoluteFromCwd, but for use when the path may -- already be absolute (in which case it is left unchanged). genericMakeAbsoluteFromCwd :: (System os, AbsRel ar) => Path os ar fd -> IO (AbsPath os fd) -- | Convert a file to a directory path. Obviously, the corresponding disk -- object won't change accordingly. The purpose of this function is to be -- an intermediate step when deriving a directory name from a file name. dirFromFile :: FilePath os ar -> DirPath os ar -- | Convert a directory to a file path. The function returns -- Nothing if the directory path is empty. The purpose of this -- function is to be an intermediate step when deriving a file name from -- a directory name. fileFromDir :: DirPath os ar -> Maybe (FilePath os ar) toFileDir :: FileDir fd => Path os ar fd -> FileDirPath os ar fromFileDir :: FileDir fd => FileDirPath os ar -> Maybe (Path os ar fd) fileFromFileDir :: FileDirPath os ar -> Maybe (FilePath os ar) dirFromFileDir :: FileDirPath os ar -> DirPath os ar toAbsRel :: AbsRel ar => Path os ar fd -> AbsRelPath os fd fromAbsRel :: AbsRel ar => AbsRelPath os fd -> Maybe (Path os ar fd) -- | Test whether a Path ar fd is absolute. -- --
-- Path.isAbsolute (Posix.absFile "/fred") ---- --
-- Path.isAbsolute (Windows.absFile "\\fred") ---- --
-- Path.isAbsolute (Windows.absFile "c:\\fred") ---- --
-- Path.isAbsolute (Windows.absFile "c:fred") --isAbsolute :: AbsRel ar => Path os ar fd -> Bool -- | Invariant - this should return True iff arg is of type Path -- Part.Rel _ -- --
-- isRelative = not . isAbsolute ---- --
-- Path.isRelative (Posix.relFile "fred") ---- --
-- Path.isRelative (Windows.relFile "fred") --isRelative :: AbsRel ar => Path os ar fd -> Bool -- | Test whether the String would correspond to an absolute path if -- interpreted as a Path. isAbsoluteString :: System os => Tagged os (String -> Bool) -- | Test whether the String would correspond to a relative path if -- interpreted as a Path. -- --
-- isRelativeString = not . isAbsoluteString --isRelativeString :: System os => Tagged os (String -> Bool) -- | Does the given filename have an extension? -- --
-- forAllAbsRel $ \x -> null (Path.takeExtension x) == not (Path.hasAnExtension x) --hasAnExtension :: FilePath os ar -> Bool -- | Does the given filename have the given extension? -- --
-- Path.hasExtension ".hs" (Posix.relFile "MyCode.hs") ---- --
-- Path.hasExtension ".hs" (Posix.relFile "MyCode.bak.hs") ---- --
-- not $ Path.hasExtension ".hs" (Posix.relFile "MyCode.hs.bak") --hasExtension :: String -> FilePath os ar -> Bool -- | This is a more flexible variant of addExtension / -- <.> which can work with files or directories -- --
-- Path.genericAddExtension (absDir "/") "x" == Posix.absDir "/.x" ---- --
-- Path.genericAddExtension (absDir "/a") "x" == Posix.absDir "/a.x" ---- --
-- Path.genericAddExtension Path.emptyFile "x" == Posix.relFile ".x" ---- --
-- Path.genericAddExtension Path.emptyFile "" == Posix.emptyFile --genericAddExtension :: FileDir fd => Path os ar fd -> String -> Path os ar fd genericDropExtension :: FileDir fd => Path os ar fd -> Path os ar fd genericDropExtensions :: FileDir fd => Path os ar fd -> Path os ar fd genericSplitExtension :: FileDir fd => Path os ar fd -> (Path os ar fd, String) genericSplitExtensions :: FileDir fd => Path os ar fd -> (Path os ar fd, String) genericTakeExtension :: FileDir fd => Path os ar fd -> String genericTakeExtensions :: FileDir fd => Path os ar fd -> String -- | Check internal integrity of the path data structure. isValid :: (System os, AbsRel ar, FileDir fd) => Path os ar fd -> Bool class System os module System.Path.Part data Abs data Rel data AbsRel data File data Dir data FileDir module System.Path.PartClass -- | This class allows selective behaviour for absolute and relative paths -- and is mostly for internal use. class Private ar => AbsRel ar -- | See https://wiki.haskell.org/Closed_world_instances for the -- used technique. switchAbsRel :: AbsRel ar => f Abs -> f Rel -> f AbsRel -> f ar class AbsRel ar => AbsOrRel ar switchAbsOrRel :: AbsOrRel ar => f Abs -> f Rel -> f ar -- | This class allows selective behaviour for file and directory paths and -- is mostly for internal use. class Private fd => FileDir fd switchFileDir :: FileDir fd => f File -> f Dir -> f FileDir -> f fd class FileDir fd => FileOrDir fd switchFileOrDir :: FileOrDir fd => f File -> f Dir -> f fd -- | 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 type Path = Path System type AbsFile = AbsFile System type RelFile = RelFile System type AbsDir = AbsDir System type RelDir = RelDir System type Abs fd = Abs System fd type Rel fd = Rel System fd type File ar = File System ar type Dir ar = Dir System ar type AbsRelFile = AbsRelFile System type AbsRelDir = AbsRelDir System type AbsFileDir = AbsFileDir System type RelFileDir = RelFileDir System type AbsRel fd = AbsRel System fd type FileDir ar = FileDir System ar type AbsRelFileDir = AbsRelFileDir System type AbsPath fd = AbsPath System fd type RelPath fd = RelPath System fd type FilePath ar = FilePath System ar type DirPath ar = DirPath System ar type AbsRelPath fd = AbsRelPath System fd type FileDirPath ar = FileDirPath System ar -- | Deprecated: Use maybePath, parsePath or path -- instead. asPath :: (AbsOrRel ar, FileOrDir fd) => String -> Path ar fd -- | Deprecated: Use relFile instead. asRelFile :: String -> RelFile -- | Deprecated: Use relDir instead. asRelDir :: String -> RelDir -- | Deprecated: Use absFile instead. asAbsFile :: String -> AbsFile -- | Deprecated: Use absDir instead. asAbsDir :: String -> AbsDir -- | Deprecated: Use relPath instead. asRelPath :: FileOrDir fd => String -> RelPath fd -- | Deprecated: Use absPath instead. asAbsPath :: FileOrDir fd => String -> AbsPath fd -- | Deprecated: Use filePath instead. asFilePath :: AbsOrRel ar => String -> FilePath ar -- | Deprecated: Use dirPath instead. asDirPath :: AbsOrRel ar => String -> DirPath ar path :: (AbsRel ar, FileDir fd) => String -> Path ar fd maybe :: (AbsRel ar, FileDir fd) => String -> Maybe (Path ar fd) -- | Deprecated: Use Path.maybe instead. maybePath :: (AbsRel ar, FileDir fd) => String -> Maybe (Path ar fd) parse :: (AbsRel ar, FileDir fd) => String -> Either String (Path ar fd) -- | Deprecated: Use Path.parse instead. parsePath :: (AbsRel ar, FileDir fd) => String -> Either String (Path ar fd) relFile :: String -> RelFile relDir :: String -> RelDir absFile :: String -> AbsFile absDir :: String -> AbsDir abs :: FileDir fd => String -> Abs fd rel :: FileDir fd => String -> Rel fd absRel :: FileDir fd => String -> AbsRel fd file :: AbsRel ar => String -> File ar dir :: AbsRel ar => String -> Dir ar fileDir :: AbsRel ar => String -> FileDir ar relPath :: FileDir fd => String -> RelPath fd absPath :: FileDir fd => String -> AbsPath fd filePath :: AbsRel ar => String -> FilePath ar dirPath :: AbsRel ar => String -> DirPath ar rootDir :: AbsDir currentDir :: RelDir emptyFile :: RelFile toString :: (AbsRel ar, FileDir fd) => Path ar fd -> String -- | Deprecated: Use System.FilePath.isAbsolute instead. isAbsoluteString :: String -> Bool -- | Deprecated: Use System.FilePath.isRelative instead. isRelativeString :: String -> Bool -- | Deprecated: Use System.FilePath.equalFilePath instead. equalFilePath :: String -> String -> Bool pathSeparator :: Char pathSeparators :: [Char] isPathSeparator :: Char -> Bool -- | Part.File extension character -- --
-- Posix.extSeparator == '.' --extSeparator :: Char -- | Is the character an extension character? -- --
-- \a -> Posix.isExtSeparator a == (a == Posix.extSeparator) --isExtSeparator :: Char -> Bool -- | The character that is used to separate the entries in the $PATH -- environment variable. searchPathSeparator :: Char -- | Is the character a file separator? -- --
-- \a -> Posix.isSearchPathSeparator a == (a == Posix.searchPathSeparator) --isSearchPathSeparator :: Char -> Bool -- | This is largely for FilePath compatibility -- | Deprecated: Use System.FilePath.addTrailingPathSeparator -- instead. addTrailingPathSeparator :: String -> String -- | This is largely for FilePath compatibility -- | Deprecated: Use System.FilePath.dropTrailingPathSeparator -- instead. dropTrailingPathSeparator :: String -> String -- | This is largely for FilePath compatibility -- | Deprecated: Use System.FilePath.hasTrailingPathSeparator -- instead. hasTrailingPathSeparator :: String -> Bool testAll :: [(String, T ())] instance System.Path.Internal.Part.System System.Path.Posix.Posix module System.Path -- | Map over the components of the path. -- --
-- Path.pathMap (map toLower) (absDir "/tmp/Reports/SpreadSheets") == Posix.absDir "/tmp/reports/spreadsheets" --pathMap :: FileDir fd => (String -> String) -> Path os ar fd -> Path os ar fd withAbsRel :: AbsRel ar => (AbsPath os fd -> a) -> (RelPath os fd -> a) -> Path os ar fd -> a withFileDir :: FileOrDir fd => (FilePath os ar -> a) -> (DirPath os ar -> a) -> Path os ar fd -> a -- | Synonym of toString intended for unqualified use. -- | Deprecated: Use Path.toString instead. getPathString :: (System os, AbsRel ar, FileDir fd) => Path os ar fd -> String idAbsRel :: AbsRelPath os fd -> AbsRelPath os fd idAbs :: AbsPath os fd -> AbsPath os fd idRel :: RelPath os fd -> RelPath os fd idFileDir :: FileDirPath os fd -> FileDirPath os fd idFile :: FilePath os fd -> FilePath os fd idDir :: DirPath os fd -> DirPath os fd -- | Examines the supplied string and constructs an absolute or relative -- path as appropriate. -- --
-- Path.mkPathAbsOrRel "/tmp" == Left (Posix.absDir "/tmp") ---- --
-- Path.mkPathAbsOrRel "tmp" == Right (Posix.relDir "tmp") ---- --
-- Path.mkPathAbsOrRel "\\tmp" == Left (Windows.absDir "\\tmp") ---- --
-- Path.mkPathAbsOrRel "d:\\tmp" == Left (Windows.absDir "d:\\tmp") ---- --
-- Path.mkPathAbsOrRel "d:tmp" == Left (Windows.absDir "d:tmp") ---- --
-- Path.mkPathAbsOrRel "tmp" == Right (Windows.relDir "tmp") ---- | Deprecated: Use Path.absRel instead. mkPathAbsOrRel :: (System os, FileDir fd) => String -> Either (AbsPath os fd) (RelPath os 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. -- | Deprecated: Don't let the path type depend on current file system -- content. Instead choose the path type according to the needed disk -- object type. mkPathFileOrDir :: (System os, AbsRel ar) => String -> IO (Maybe (Either (FilePath os ar) (DirPath os ar))) -- | Convert a String into an AbsPath by interpreting it as -- relative to the supplied directory if necessary. -- --
-- Path.mkAbsPath (absDir "/tmp") "foo.txt" == Posix.absFile "/tmp/foo.txt" ---- --
-- Path.mkAbsPath (absDir "/tmp") "/etc/foo.txt" == Posix.absFile "/etc/foo.txt" ---- | Deprecated: Use Path.dynamicMakeAbsolute instead. mkAbsPath :: (System os, FileDir fd) => AbsDir os -> String -> AbsPath os fd -- | Convert a String into an AbsPath by interpreting it as -- relative to the cwd if necessary. -- | Deprecated: Use Path.dynamicMakeAbsoluteFromCwd instead. mkAbsPathFromCwd :: (System os, FileDir fd) => String -> IO (AbsPath os fd) -- | Infix variant of combine. -- --
-- Posix.toString (Posix.absDir "/tmp" </> Posix.relFile "file.txt") == "/tmp/file.txt" ---- --
-- Posix.toString (Posix.absDir "/tmp" </> Posix.relDir "dir" </> Posix.relFile "file.txt") == "/tmp/dir/file.txt" ---- --
-- Posix.toString (Posix.relDir "dir" </> Posix.relFile "file.txt") == "dir/file.txt" ---- --
-- Windows.toString (Windows.absDir "\\tmp" </> Windows.relFile "file.txt") == "\\tmp\\file.txt" ---- --
-- Windows.toString (Windows.absDir "c:\\tmp" </> Windows.relFile "file.txt") == "c:\\tmp\\file.txt" ---- --
-- Windows.toString (Windows.absDir "c:tmp" </> Windows.relFile "file.txt") == "c:tmp\\file.txt" ---- --
-- Windows.toString (Windows.absDir "c:\\" </> Windows.relDir "tmp" </> Windows.relFile "file.txt") == "c:\\tmp\\file.txt" ---- --
-- Windows.toString (Windows.absDir "c:" </> Windows.relDir "tmp" </> Windows.relFile "file.txt") == "c:tmp\\file.txt" ---- --
-- Windows.toString (Windows.relDir "dir" </> Windows.relFile "file.txt") == "dir\\file.txt" --(>) :: DirPath os ar -> RelPath os fd -> Path os ar fd infixr 5 > -- | Infix variant of addExtension. 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 os ar -> String -> FilePath os ar infixl 7 <.> (<++>) :: FilePath os ar -> String -> FilePath os ar infixl 7 <++> -- | Add an extension, even if there is already one there. E.g. -- addExtension "foo.txt" "bat" -> "foo.txt.bat". -- --
-- Path.addExtension (relFile "file.txt") "bib" == Posix.relFile "file.txt.bib" ---- --
-- Path.addExtension (relFile "file.") ".bib" == Posix.relFile "file..bib" ---- --
-- Path.addExtension (relFile "file") ".bib" == Posix.relFile "file.bib" ---- --
-- Path.addExtension Path.emptyFile "bib" == Posix.relFile ".bib" ---- --
-- Path.addExtension Path.emptyFile ".bib" == Posix.relFile ".bib" ---- --
-- Path.takeFileName (Path.addExtension Path.emptyFile "ext") == Posix.relFile ".ext" --addExtension :: FilePath os ar -> String -> FilePath os ar -- | Join an (absolute or relative) directory path with a relative (file or -- directory) path to form a new path. -- --
-- \p -> Path.combine Path.currentDir p == (p::Default.RelDir) --combine :: DirPath os ar -> RelPath os fd -> Path os ar fd -- | Remove last extension, and the "." preceding it. -- --
-- forAllAbsRel $ \x -> Path.dropExtension x == fst (Path.splitExtension x) --dropExtension :: FilePath os ar -> FilePath os ar -- | Drop all extensions -- --
-- forAllAbsRel $ \x -> not $ Path.hasAnExtension (Path.dropExtensions x) --dropExtensions :: FilePath os ar -> FilePath os ar -- | Synonym for takeDirectory dropFileName :: FilePath os ar -> DirPath os ar -- | Set the extension of a file, overwriting one if already present. -- --
-- Path.replaceExtension (relFile "file.txt") ".bob" == Posix.relFile "file.bob" ---- --
-- Path.replaceExtension (relFile "file.txt") "bob" == Posix.relFile "file.bob" ---- --
-- Path.replaceExtension (relFile "file") ".bob" == Posix.relFile "file.bob" ---- --
-- Path.replaceExtension (relFile "file.txt") "" == Posix.relFile "file" ---- --
-- Path.replaceExtension (relFile "file.fred.bob") "txt" == Posix.relFile "file.fred.txt" --replaceExtension :: FilePath os ar -> String -> FilePath os ar replaceBaseName :: FilePath os ar -> String -> FilePath os ar replaceDirectory :: FilePath os ar1 -> DirPath os ar2 -> FilePath os ar2 replaceFileName :: FilePath os ar -> String -> FilePath os ar -- | Split on the extension. addExtension is the inverse. -- --
-- forAllAbsRel $ \x -> uncurry (<.>) (Path.splitExtension x) == x ---- --
-- forAllAbsRel $ \x -> uncurry Path.addExtension (Path.splitExtension x) == x ---- --
-- Path.splitExtension (relFile "file.txt") == (Posix.relFile "file",".txt") ---- --
-- Path.splitExtension (relFile ".bashrc") == (Posix.emptyFile, ".bashrc") ---- --
-- Path.splitExtension (relFile "file") == (Posix.relFile "file","") ---- --
-- Path.splitExtension (relFile "file/file.txt") == (Posix.relFile "file/file",".txt") ---- --
-- Path.splitExtension (relFile "file.txt/boris") == (Posix.relFile "file.txt/boris","") ---- --
-- Path.splitExtension (relFile "file.txt/boris.ext") == (Posix.relFile "file.txt/boris",".ext") ---- --
-- Path.splitExtension (relFile "file/path.txt.bob.fred") == (Posix.relFile "file/path.txt.bob",".fred") --splitExtension :: FilePath os ar -> (FilePath os ar, String) -- | Split on all extensions -- --
-- Path.splitExtensions (relFile "file.tar.gz") == (Posix.relFile "file",".tar.gz") ---- --
-- \p -> uncurry (<.>) (Path.splitExtension p) == (p::Default.AbsFile) --splitExtensions :: FilePath os ar -> (FilePath os ar, String) -- |
-- \p -> uncurry Path.combine (Path.splitFileName p) == (p::Default.AbsFile) --splitFileName :: FilePath os ar -> (DirPath os ar, RelFile os) -- |
-- \p -> (uncurry Path.combine <$> Path.splitDirName p) == toMaybe (not $ Default.isDrive p) (p::Default.AbsDir) --splitDirName :: DirPath os ar -> Maybe (DirPath os ar, RelDir os) -- | Get the basename of a file -- --
-- Path.takeBaseName (absFile "/tmp/somedir/myfile.txt") == Posix.relFile "myfile" ---- --
-- Path.takeBaseName (relFile "./myfile.txt") == Posix.relFile "myfile" ---- --
-- Path.takeBaseName (relFile "myfile.txt") == Posix.relFile "myfile" --takeBaseName :: FilePath os ar -> RelFile os takeDirectory :: FilePath os ar -> DirPath os ar takeSuperDirectory :: DirPath os ar -> Maybe (DirPath os ar) -- | Get the extension of a file, returns "" for no extension, -- .ext otherwise. -- --
-- forAllAbsRel $ \x -> Path.takeExtension x == snd (Path.splitExtension x) ---- --
-- forAllAbsRel $ \x -> Path.takeExtension (Path.addExtension x "ext") == ".ext" ---- --
-- forAllAbsRel $ \x -> Path.takeExtension (Path.replaceExtension x "ext") == ".ext" --takeExtension :: FilePath os ar -> String -- | Get all extensions -- --
-- Path.takeExtensions (Posix.relFile "file.tar.gz") == ".tar.gz" --takeExtensions :: FilePath os ar -> String -- | Get the filename component of a file path (ie stripping all parent -- dirs) -- --
-- Path.takeFileName (absFile "/tmp/somedir/myfile.txt") == Posix.relFile "myfile.txt" ---- --
-- Path.takeFileName (relFile "./myfile.txt") == Posix.relFile "myfile.txt" ---- --
-- Path.takeFileName (relFile "myfile.txt") == Posix.relFile "myfile.txt" ---- --
-- \p -> Path.toString (Path.takeFileName p) `isSuffixOf` Path.toString (p::Default.AbsFile) --takeFileName :: FilePath os ar -> RelFile os -- |
-- \p -> fmap (\d -> toString d `isSuffixOf` toString p) (takeDirName p) == toMaybe (not $ isDrive p) True --takeDirName :: DirPath os ar -> Maybe (RelDir os) mapFileName :: (String -> String) -> FilePath os ar -> FilePath os ar mapFileNameF :: Functor f => (String -> f String) -> FilePath os ar -> f (FilePath os ar) -- | Constructs a RelPath from a list of components. It is an -- unchecked error if the path components contain path separators. It is -- an unchecked error if a RelFile path is empty. -- --
-- Path.joinPath ["tmp","someDir","dir"] == Posix.relDir "tmp/someDir/dir" ---- --
-- Path.joinPath ["tmp","someDir","file.txt"] == Posix.relFile "tmp/someDir/file.txt" --joinPath :: FileDir fd => [String] -> RelPath os fd -- | Currently just transforms: -- --
-- Path.normalise (absFile "/tmp/fred/./jim/./file") == Posix.absFile "/tmp/fred/jim/file" --normalise :: System os => Path os ar fd -> Path os ar fd -- | Deconstructs a path into its components. -- --
-- Path.splitPath (Posix.absDir "/tmp/someDir/mydir.dir") == (True, map relDir ["tmp","someDir","mydir.dir"], Nothing) ---- --
-- Path.splitPath (Posix.absFile "/tmp/someDir/myfile.txt") == (True, map relDir ["tmp","someDir"], Just $ relFile "myfile.txt") --splitPath :: (AbsRel ar, FileOrDir fd) => Path os ar fd -> (Bool, [RelDir os], Maybe (RelFile os)) -- | 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. -- --
-- Path.makeRelative (absDir "/tmp/somedir") (absFile "/tmp/somedir/anotherdir/file.txt") == Posix.relFile "anotherdir/file.txt" ---- --
-- Path.makeRelative (absDir "/tmp/somedir") (absDir "/tmp/somedir/anotherdir/dir") == Posix.relDir "anotherdir/dir" ---- --
-- Path.makeRelative (absDir "c:\\tmp\\somedir") (absFile "C:\\Tmp\\SomeDir\\AnotherDir\\File.txt") == Windows.relFile "AnotherDir\\File.txt" ---- --
-- Path.makeRelative (absDir "c:\\tmp\\somedir") (absDir "c:\\tmp\\somedir\\anotherdir\\dir") == Windows.relDir "anotherdir\\dir" ---- --
-- Path.makeRelative (absDir "c:tmp\\somedir") (absDir "c:tmp\\somedir\\anotherdir\\dir") == Windows.relDir "anotherdir\\dir" --makeRelative :: (System os, FileDir fd) => AbsDir os -> AbsPath os fd -> RelPath os fd makeRelativeMaybe :: (System os, FileDir fd) => AbsDir os -> AbsPath os fd -> Maybe (RelPath os fd) -- | Joins an absolute directory with a relative path to construct a new -- absolute path. -- --
-- Path.makeAbsolute (absDir "/tmp") (relFile "file.txt") == Posix.absFile "/tmp/file.txt" ---- --
-- Path.makeAbsolute (absDir "/tmp") (relFile "adir/file.txt") == Posix.absFile "/tmp/adir/file.txt" ---- --
-- Path.makeAbsolute (absDir "/tmp") (relDir "adir/dir") == Posix.absDir "/tmp/adir/dir" ---- --
-- \base p -> Default.toString p `isSuffixOf` Path.toString (Path.makeAbsolute base (Path.idFile p)) ---- --
-- \base p -> Default.toString base `isPrefixOf` Path.toString (Path.makeAbsolute base (Path.idFile p)) --makeAbsolute :: System os => AbsDir os -> RelPath os fd -> AbsPath os fd -- | Converts a relative path into an absolute one by prepending the -- current working directory. makeAbsoluteFromCwd :: System os => RelPath os fd -> IO (AbsPath os fd) dynamicMakeAbsolute :: System os => AbsDir os -> AbsRelPath os fd -> AbsPath os fd dynamicMakeAbsoluteFromCwd :: System os => AbsRelPath os fd -> IO (AbsPath os fd) -- | As for makeAbsolute, but for use when the path may already be -- absolute (in which case it is left unchanged). You should avoid the -- use of genericMakeAbsolute-type functions, because then you -- avoid to absolutize a path that was already absolutized. -- --
-- Path.genericMakeAbsolute (absDir "/tmp") (relFile "file.txt") == Posix.absFile "/tmp/file.txt" ---- --
-- Path.genericMakeAbsolute (absDir "/tmp") (relFile "adir/file.txt") == Posix.absFile "/tmp/adir/file.txt" ---- --
-- Path.genericMakeAbsolute (absDir "/tmp") (absFile "/adir/file.txt") == Posix.absFile "/adir/file.txt" --genericMakeAbsolute :: (System os, AbsRel ar) => AbsDir os -> Path os ar fd -> AbsPath os fd -- | As for makeAbsoluteFromCwd, but for use when the path may -- already be absolute (in which case it is left unchanged). genericMakeAbsoluteFromCwd :: (System os, AbsRel ar) => Path os ar fd -> IO (AbsPath os fd) -- | Convert a file to a directory path. Obviously, the corresponding disk -- object won't change accordingly. The purpose of this function is to be -- an intermediate step when deriving a directory name from a file name. dirFromFile :: FilePath os ar -> DirPath os ar -- | Convert a directory to a file path. The function returns -- Nothing if the directory path is empty. The purpose of this -- function is to be an intermediate step when deriving a file name from -- a directory name. fileFromDir :: DirPath os ar -> Maybe (FilePath os ar) toFileDir :: FileDir fd => Path os ar fd -> FileDirPath os ar fromFileDir :: FileDir fd => FileDirPath os ar -> Maybe (Path os ar fd) fileFromFileDir :: FileDirPath os ar -> Maybe (FilePath os ar) dirFromFileDir :: FileDirPath os ar -> DirPath os ar toAbsRel :: AbsRel ar => Path os ar fd -> AbsRelPath os fd fromAbsRel :: AbsRel ar => AbsRelPath os fd -> Maybe (Path os ar fd) -- | Test whether a Path ar fd is absolute. -- --
-- Path.isAbsolute (Posix.absFile "/fred") ---- --
-- Path.isAbsolute (Windows.absFile "\\fred") ---- --
-- Path.isAbsolute (Windows.absFile "c:\\fred") ---- --
-- Path.isAbsolute (Windows.absFile "c:fred") --isAbsolute :: AbsRel ar => Path os ar fd -> Bool -- | Invariant - this should return True iff arg is of type Path -- Part.Rel _ -- --
-- isRelative = not . isAbsolute ---- --
-- Path.isRelative (Posix.relFile "fred") ---- --
-- Path.isRelative (Windows.relFile "fred") --isRelative :: AbsRel ar => Path os ar fd -> Bool -- | Does the given filename have an extension? -- --
-- forAllAbsRel $ \x -> null (Path.takeExtension x) == not (Path.hasAnExtension x) --hasAnExtension :: FilePath os ar -> Bool -- | Does the given filename have the given extension? -- --
-- Path.hasExtension ".hs" (Posix.relFile "MyCode.hs") ---- --
-- Path.hasExtension ".hs" (Posix.relFile "MyCode.bak.hs") ---- --
-- not $ Path.hasExtension ".hs" (Posix.relFile "MyCode.hs.bak") --hasExtension :: String -> FilePath os ar -> Bool -- | This is a more flexible variant of addExtension / -- <.> which can work with files or directories -- --
-- Path.genericAddExtension (absDir "/") "x" == Posix.absDir "/.x" ---- --
-- Path.genericAddExtension (absDir "/a") "x" == Posix.absDir "/a.x" ---- --
-- Path.genericAddExtension Path.emptyFile "x" == Posix.relFile ".x" ---- --
-- Path.genericAddExtension Path.emptyFile "" == Posix.emptyFile --genericAddExtension :: FileDir fd => Path os ar fd -> String -> Path os ar fd genericDropExtension :: FileDir fd => Path os ar fd -> Path os ar fd genericDropExtensions :: FileDir fd => Path os ar fd -> Path os ar fd genericSplitExtension :: FileDir fd => Path os ar fd -> (Path os ar fd, String) genericSplitExtensions :: FileDir fd => Path os ar fd -> (Path os ar fd, String) genericTakeExtension :: FileDir fd => Path os ar fd -> String genericTakeExtensions :: FileDir fd => Path os ar fd -> String -- | Check internal integrity of the path data structure. isValid :: (System os, AbsRel ar, FileDir fd) => Path os ar fd -> Bool -- | 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 :: AbsRel ar => FilePath ar -> IOMode -> (Handle -> IO r) -> IO r openFile :: AbsRel ar => FilePath ar -> IOMode -> IO Handle readFile :: AbsRel ar => FilePath ar -> IO String writeFile :: AbsRel ar => FilePath ar -> String -> IO () appendFile :: AbsRel ar => FilePath ar -> String -> IO () withBinaryFile :: AbsRel ar => FilePath ar -> IOMode -> (Handle -> IO r) -> IO r openBinaryFile :: AbsRel ar => FilePath ar -> IOMode -> IO Handle openTempFile :: AbsRel ar => DirPath ar -> RelFile -> IO (AbsFile, Handle) openBinaryTempFile :: AbsRel 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 -- | The implementation of mfix for IO. If the function -- passed to fixIO inspects its argument, the resulting action -- will throw FixIOException. 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: -- --
-- import qualified System.Path.IO as PathIO -- import qualified System.Path as Path -- import System.Path.Directory (createDirectory) --module System.Path.Directory createDirectory :: AbsRel ar => DirPath ar -> IO () createDirectoryIfMissing :: AbsRel ar => Bool -> DirPath ar -> IO () removeDirectory :: AbsRel ar => DirPath ar -> IO () removeDirectoryRecursive :: AbsRel ar => DirPath ar -> IO () renameDirectory :: (AbsRel ar1, AbsRel ar2) => DirPath ar1 -> DirPath ar2 -> IO () -- | Retrieve the contents of a directory without any directory prefixes. -- In contrast to getDirectoryContents, exclude special -- directories "." and "..". getDirectoryContents :: AbsRel ar => DirPath ar -> IO [RelFileDir] -- | Retrieve the contents of a directory path (which may be relative) as -- absolute paths absDirectoryContents :: AbsRel 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 :: AbsRel ar => DirPath ar -> IO ([RelDir], [RelFile]) -- | A convenient alternative to relDirectoryContents if you only -- want files. filesInDir :: AbsRel ar => DirPath ar -> IO [RelFile] -- | A convenient alternative to relDirectoryContents if you only -- want directories. dirsInDir :: AbsRel ar => DirPath ar -> IO [RelDir] getCurrentDirectory :: IO AbsDir setCurrentDirectory :: AbsRel ar => DirPath ar -> IO () getHomeDirectory :: IO AbsDir getAppUserDataDirectory :: String -> IO AbsDir getUserDocumentsDirectory :: IO AbsDir getTemporaryDirectory :: IO AbsDir removeFile :: AbsRel ar => FilePath ar -> IO () renameFile :: (AbsRel ar1, AbsRel ar2) => FilePath ar1 -> FilePath ar2 -> IO () copyFile :: (AbsRel ar1, AbsRel ar2) => FilePath ar1 -> FilePath ar2 -> IO () canonicalizePath :: (AbsRel ar, FileDir fd) => Path ar fd -> IO (AbsPath fd) makeRelativeToCurrentDirectory :: (AbsRel ar, FileDir fd) => Path ar fd -> IO (RelPath fd) findExecutable :: String -> IO (Maybe AbsFile) doesFileExist :: AbsRel ar => FilePath ar -> IO Bool doesDirectoryExist :: AbsRel ar => DirPath ar -> IO Bool data Permissions getPermissions :: (AbsRel ar, FileDir fd) => Path ar fd -> IO Permissions setPermissions :: (AbsRel ar, FileDir fd) => Path ar fd -> Permissions -> IO () getModificationTime :: (AbsRel ar, FileDir fd) => Path ar fd -> IO UTCTime -- | 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 type Path = Path System type AbsFile = AbsFile System type RelFile = RelFile System type AbsDir = AbsDir System type RelDir = RelDir System type Abs fd = Abs System fd type Rel fd = Rel System fd type File ar = File System ar type Dir ar = Dir System ar type AbsRelFile = AbsRelFile System type AbsRelDir = AbsRelDir System type AbsFileDir = AbsFileDir System type RelFileDir = RelFileDir System type AbsRel fd = AbsRel System fd type FileDir ar = FileDir System ar type AbsRelFileDir = AbsRelFileDir System type AbsPath fd = AbsPath System fd type RelPath fd = RelPath System fd type FilePath ar = FilePath System ar type DirPath ar = DirPath System ar type AbsRelPath fd = AbsRelPath System fd type FileDirPath ar = FileDirPath System ar -- | Deprecated: Use maybePath, parsePath or path -- instead. asPath :: (AbsOrRel ar, FileOrDir fd) => String -> Path ar fd -- | Deprecated: Use relFile instead. asRelFile :: String -> RelFile -- | Deprecated: Use relDir instead. asRelDir :: String -> RelDir -- | Deprecated: Use absFile instead. asAbsFile :: String -> AbsFile -- | Deprecated: Use absDir instead. asAbsDir :: String -> AbsDir -- | Deprecated: Use relPath instead. asRelPath :: FileOrDir fd => String -> RelPath fd -- | Deprecated: Use absPath instead. asAbsPath :: FileOrDir fd => String -> AbsPath fd -- | Deprecated: Use filePath instead. asFilePath :: AbsOrRel ar => String -> FilePath ar -- | Deprecated: Use dirPath instead. asDirPath :: AbsOrRel ar => String -> DirPath ar path :: (AbsRel ar, FileDir fd) => String -> Path ar fd maybe :: (AbsRel ar, FileDir fd) => String -> Maybe (Path ar fd) -- | Deprecated: Use Path.maybe instead. maybePath :: (AbsRel ar, FileDir fd) => String -> Maybe (Path ar fd) parse :: (AbsRel ar, FileDir fd) => String -> Either String (Path ar fd) -- | Deprecated: Use Path.parse instead. parsePath :: (AbsRel ar, FileDir fd) => String -> Either String (Path ar fd) relFile :: String -> RelFile relDir :: String -> RelDir absFile :: String -> AbsFile absDir :: String -> AbsDir abs :: FileDir fd => String -> Abs fd rel :: FileDir fd => String -> Rel fd absRel :: FileDir fd => String -> AbsRel fd file :: AbsRel ar => String -> File ar dir :: AbsRel ar => String -> Dir ar fileDir :: AbsRel ar => String -> FileDir ar relPath :: FileDir fd => String -> RelPath fd absPath :: FileDir fd => String -> AbsPath fd filePath :: AbsRel ar => String -> FilePath ar dirPath :: AbsRel ar => String -> DirPath ar rootDir :: AbsDir currentDir :: RelDir emptyFile :: RelFile toString :: (AbsRel ar, FileDir fd) => Path ar fd -> String -- | Deprecated: Use System.FilePath.isAbsolute instead. isAbsoluteString :: String -> Bool -- | Deprecated: Use System.FilePath.isRelative instead. isRelativeString :: String -> Bool -- | Deprecated: Use System.FilePath.equalFilePath instead. equalFilePath :: String -> String -> Bool pathSeparator :: Char pathSeparators :: [Char] isPathSeparator :: Char -> Bool -- | Part.File extension character -- --
-- Posix.extSeparator == '.' --extSeparator :: Char -- | Is the character an extension character? -- --
-- \a -> Posix.isExtSeparator a == (a == Posix.extSeparator) --isExtSeparator :: Char -> Bool -- | The character that is used to separate the entries in the $PATH -- environment variable. searchPathSeparator :: Char -- | Is the character a file separator? -- --
-- \a -> Posix.isSearchPathSeparator a == (a == Posix.searchPathSeparator) --isSearchPathSeparator :: Char -> Bool -- | This is largely for FilePath compatibility -- | Deprecated: Use System.FilePath.addTrailingPathSeparator -- instead. addTrailingPathSeparator :: String -> String -- | This is largely for FilePath compatibility -- | Deprecated: Use System.FilePath.dropTrailingPathSeparator -- instead. dropTrailingPathSeparator :: String -> String -- | This is largely for FilePath compatibility -- | Deprecated: Use System.FilePath.hasTrailingPathSeparator -- instead. hasTrailingPathSeparator :: String -> Bool testAll :: [(String, T ())] instance System.Path.Internal.Part.System System.Path.Windows.Windows