| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Data.Path
Contents
- data Path rel
- type AbsPath = Path Absolute
- type RelPath = Path Relative
- data Absolute
- data Relative
- data PathPiece
- data LastPathPiece
- data Extension
- relpath :: FilePath -> Maybe RelPath
- abspath :: FilePath -> Maybe AbsPath
- ext :: String -> Maybe Extension
- ground :: AbsPath -> FilePath -> Maybe AbsPath
- unsafeRelPathError :: FilePath -> RelPath
- unsafeAbsPathError :: FilePath -> AbsPath
- unsafePathPieceError :: String -> PathPiece
- unsafeLastPieceError :: String -> LastPathPiece
- unsafeExtError :: String -> Extension
- toRelFilePath :: RelPath -> FilePath
- toAbsFilePath :: AbsPath -> FilePath
- takeExtension :: Path rel -> Maybe Extension
- takeExtensions :: Path rel -> [Extension]
- addExtension :: Path rel -> Extension -> Path rel
- (<.>) :: Path rel -> Extension -> Path rel
- addExtensions :: Path rel -> [Extension] -> Path rel
- dropExtensionExact :: Path rel -> Maybe (Path rel)
- dropExtension :: Path rel -> Path rel
- dropExtensions :: Path rel -> Path rel
- replaceExtensionExact :: Path rel -> Extension -> Maybe (Path rel)
- replaceExtension :: Path rel -> Extension -> Path rel
- (-<.>) :: Path rel -> Extension -> Path rel
- replaceExtensions :: Path rel -> Extension -> Path rel
- replaceExtensionss :: Path rel -> [Extension] -> Path rel
- stripExtension :: Path rel -> Extension -> Maybe (Path rel)
- stripExtensions :: Path rel -> [Extension] -> Maybe (Path rel)
- splitExtension :: Path rel -> Maybe (Path rel, Extension)
- splitExtensions :: Path rel -> (Path rel, [Extension])
- hasExtension :: Path rel -> Bool
- takeFileNameExact :: Path rel -> Maybe RelPath
- takeFileName :: Path rel -> RelPath
- dropFileNameExact :: Path rel -> Maybe (Path rel)
- dropFileName :: Path rel -> Path rel
- replaceFileNameExact :: Path rel -> PathPiece -> Maybe (Path rel)
- replaceFileName :: Path rel -> PathPiece -> Path rel
- takeBaseNameExact :: Path rel -> Maybe LastPathPiece
- takeBaseName :: Path rel -> LastPathPiece
- replaceBaseNameExact :: Path rel -> LastPathPiece -> Maybe (Path rel)
- replaceBaseName :: Path rel -> LastPathPiece -> Path rel
- replaceDirectoryExact :: Path r -> Path s -> Maybe (Path s)
- replaceDirectory :: Path r -> Path s -> Path s
- combineExact :: Path rel -> RelPath -> Maybe (Path rel)
- combine :: Path rel -> RelPath -> Path rel
- (</>) :: Path rel -> RelPath -> Path rel
- splitPath :: Path rel -> [PathPiece]
- joinPath :: [PathPiece] -> Maybe (Path rel)
- pathSeparator :: Char
- pathSeparators :: [Char]
- isPathSeparator :: Char -> Bool
- extensionSeparator :: Char
- extensionSeparators :: [Char]
- isExtensionSeparator :: Char -> Bool
Safe Path Types
Instances
| Eq (Path rel) Source # | |
| Data rel => Data (Path rel) Source # | |
| Show (Path rel) Source # | |
| Show (Path Relative) Source # | |
| Show (Path Absolute) Source # | |
| IsString (Path Relative) Source # | ONLY for |
| IsString (Path Absolute) Source # | ONLY for |
| Generic (Path rel) Source # | |
| Validity (Path rel) Source # | |
| type Rep (Path rel) Source # | |
Safe path helper types
data LastPathPiece Source #
Instances
| Eq LastPathPiece Source # | |
| Data LastPathPiece Source # | |
| Show LastPathPiece Source # | |
| IsString LastPathPiece Source # | ONLY for |
| Generic LastPathPiece Source # | |
| Validity LastPathPiece Source # | |
| type Rep LastPathPiece Source # | |
Constructing safe values
Constructing safe values safely
ext :: String -> Maybe Extension Source #
Construct an extension safely
>>>ext "extension"Just extension>>>ext ".ext"Nothing>>>ext ""Nothing
ground :: AbsPath -> FilePath -> Maybe AbsPath Source #
Ground a filepath on an absolute path.
This will try to parse the given FilePath as an absolute path and take it
if that works. Otherwise it will try to parse it an a relative path and
append it to the given AbsPath
>>>ground "/home/user" "relative/path"Just /home/user/relative/path>>>ground "/home/user" "/absolute/path"Just /absolute/path>>>ground "/home/user" "."Just /home/user>>>ground "/home/user" "/"Just />>>ground "/" "."Just />>>ground "/anything" ""Nothing
Constructing safe values unsafely
unsafeRelPathError :: FilePath -> RelPath Source #
unsafeAbsPathError :: FilePath -> AbsPath Source #
unsafeExtError :: String -> Extension Source #
Rendering safe paths to FilePaths
Functions involving extension
Inspecting extensions
takeExtension :: Path rel -> Maybe Extension Source #
Take the last extension of a filepath
>>>takeExtension ("/directory/path.ext" :: AbsPath)Just ext>>>takeExtension ("file.tar.gz" :: RelPath)Just gz>>>takeExtension ("file" :: RelPath)Nothing
Replaces System.FilePath.takeExtension
takeExtensions :: Path rel -> [Extension] Source #
Take all extensions of a given path in the form of a list
>>>takeExtensions ("/directory/path.ext" :: AbsPath)[ext]>>>takeExtensions ("file.tar.gz" :: RelPath)[tar,gz]
Replaces System.FilePath.takeExtensions
Adding extensions
addExtension :: Path rel -> Extension -> Path rel Source #
Add an extension to a path
>>>addExtension "/directory/path" "ext" :: AbsPath/directory/path.ext>>>addExtension "directory/path" "ext" :: RelPathdirectory/path.ext
This will not override the extension if there already is an extension. It will only add the given extension on top of it
>>>addExtension "/directory/path.ext1" "ext2" :: AbsPath/directory/path.ext1.ext2>>>addExtension "directory/path.ext1" "ext2" :: RelPathdirectory/path.ext1.ext2
This will not add an extension if the path is empty.
>>>addExtension "." "ext" :: RelPath.>>>addExtension "/" "ext" :: AbsPath/
Replaces System.FilePath.addExtension
(<.>) :: Path rel -> Extension -> Path rel Source #
Add an extension to a path (equivalent to addExtension)
>>>"/directory/path" <.> "ext" :: AbsPath/directory/path.ext>>>"directory/path" <.> "ext" :: RelPathdirectory/path.ext>>>"/directory/path.ext1" <.> "ext2" :: AbsPath/directory/path.ext1.ext2>>>"directory/path.ext1" <.> "ext2" :: RelPathdirectory/path.ext1.ext2>>>"." <.> "ext" :: RelPath.>>>"/" <.> "ext" :: AbsPath/
Replaces System.FilePath.(.)
addExtensions :: Path rel -> [Extension] -> Path rel Source #
Add a list of extensions to a path
>>>addExtensions "/directory/path" ["ext1", "ext2"] :: AbsPath/directory/path.ext1.ext2>>>addExtensions "directory/path" ["ext1", "ext2"] :: RelPathdirectory/path.ext1.ext2
>>>addExtensions "/directory/path.ext1" ["ext2", "ext3"] :: AbsPath/directory/path.ext1.ext2.ext3>>>addExtensions "directory/path.ext1" ["ext2", "ext3"] :: RelPathdirectory/path.ext1.ext2.ext3
>>>addExtensions "." ["ext1", "ext2"] :: RelPath.>>>addExtensions "/" ["ext1", "ext2"] :: AbsPath/
This operation is an identity function if the given list of extensions is empty.
Removing extensions
dropExtensionExact :: Path rel -> Maybe (Path rel) Source #
Drop the last extension of a path, exactly
This will fail if the given path has no extensions
>>>dropExtensionExact "dir/file.ext1.ext2" :: Maybe RelPathJust dir/file.ext1>>>dropExtensionExact "dir/file.ext" :: Maybe RelPathJust dir/file>>>dropExtensionExact "dir/file" :: Maybe RelPathNothing>>>dropExtensionExact "/dir/file.ext1.ext2" :: Maybe AbsPathJust /dir/file.ext1>>>dropExtensionExact "/dir/file.ext" :: Maybe AbsPathJust /dir/file>>>dropExtensionExact "/dir/file" :: Maybe AbsPathNothing>>>dropExtensionExact "." :: Maybe RelPathNothing>>>dropExtensionExact "/" :: Maybe AbsPathNothing
dropExtension :: Path rel -> Path rel Source #
Drop the last extension of a path
>>>dropExtension "dir/file.ext1.ext2" :: RelPathdir/file.ext1>>>dropExtension "dir/file.ext" :: RelPathdir/file>>>dropExtension "dir/file" :: RelPathdir/file>>>dropExtension "/dir/file.ext1.ext2" :: AbsPath/dir/file.ext1>>>dropExtension "/dir/file.ext" :: AbsPath/dir/file>>>dropExtension "/dir/file" :: AbsPath/dir/file>>>dropExtension "." :: RelPath.>>>dropExtension "/" :: AbsPath/
Replaces System.FilePath.dropExtension
dropExtensions :: Path rel -> Path rel Source #
Drop all extensions of a path
>>>dropExtensions "dir/file.ext1.ext2" :: RelPathdir/file>>>dropExtensions "dir/file.ext" :: RelPathdir/file>>>dropExtensions "dir/file" :: RelPathdir/file>>>dropExtensions "/dir/file.ext1.ext2" :: AbsPath/dir/file>>>dropExtensions "/dir/file.ext" :: AbsPath/dir/file>>>dropExtensions "/dir/file" :: AbsPath/dir/file>>>dropExtensions "." :: RelPath.>>>dropExtensions "/" :: AbsPath/
Replaces System.FilePath.dropExtensions
Replacing extensions
replaceExtensionExact :: Path rel -> Extension -> Maybe (Path rel) Source #
Replace the last extension of a path, exactly
This will fail if the given path has no extension
>>>replaceExtensionExact "dir/file.ext1.ext2" "ext3" :: Maybe RelPathJust dir/file.ext1.ext3>>>replaceExtensionExact "dir/file.ext1" "ext2" :: Maybe RelPathJust dir/file.ext2>>>replaceExtensionExact "dir/file" "ext" :: Maybe RelPathNothing>>>replaceExtensionExact "/dir/file.ext1.ext2" "ext3" :: Maybe AbsPathJust /dir/file.ext1.ext3>>>replaceExtensionExact "/dir/file.ext1" "ext2" :: Maybe AbsPathJust /dir/file.ext2>>>replaceExtensionExact "/dir/file" "ext" :: Maybe AbsPathNothing>>>replaceExtensionExact "." "ext" :: Maybe RelPathNothing>>>replaceExtensionExact "/" "ext" :: Maybe AbsPathNothing
replaceExtension :: Path rel -> Extension -> Path rel Source #
Replace the last extension of a path
This will first remove one extension and then add the given extension.
replaceExtension path extension = dropExtension path <.> extension
>>>replaceExtension "dir/file.ext1.ext2" "ext3" :: RelPathdir/file.ext1.ext3>>>replaceExtension "dir/file.ext1" "ext2" :: RelPathdir/file.ext2>>>replaceExtension "dir/file" "ext" :: RelPathdir/file.ext>>>replaceExtension "/dir/file.ext1.ext2" "ext3" :: AbsPath/dir/file.ext1.ext3>>>replaceExtension "/dir/file.ext1" "ext2" :: AbsPath/dir/file.ext2>>>replaceExtension "/dir/file" "ext" :: AbsPath/dir/file.ext>>>replaceExtension "." "ext" :: RelPath.>>>replaceExtension "/" "ext" :: AbsPath/
Replaces System.FilePath.replaceExtension
(-<.>) :: Path rel -> Extension -> Path rel Source #
Replace the last extension of a path (equivalent to replaceExtension)
>>>"dir/file.ext1.ext2" -<.> "ext3" :: RelPathdir/file.ext1.ext3>>>"dir/file.ext1" -<.> "ext2" :: RelPathdir/file.ext2>>>"dir/file" -<.> "ext" :: RelPathdir/file.ext>>>"/dir/file.ext1.ext2" -<.> "ext3" :: AbsPath/dir/file.ext1.ext3>>>"/dir/file.ext1" -<.> "ext2" :: AbsPath/dir/file.ext2>>>"/dir/file" -<.> "ext" :: AbsPath/dir/file.ext>>>"." -<.> "ext" :: RelPath.>>>"/" -<.> "ext" :: AbsPath/
Replaces System.FilePath.(-.)
replaceExtensions :: Path rel -> Extension -> Path rel Source #
Replace all the extensions of a path with the given extension
>>>replaceExtensions "dir/file.ext1.ext2" "ext3" :: RelPathdir/file.ext3>>>replaceExtensions "dir/file.ext1" "ext3" :: RelPathdir/file.ext3>>>replaceExtensions "dir/file" "ext3" :: RelPathdir/file.ext3>>>replaceExtensions "/dir/file.ext1.ext2" "ext3" :: AbsPath/dir/file.ext3>>>replaceExtensions "/dir/file.ext1" "ext3" :: AbsPath/dir/file.ext3>>>replaceExtensions "/dir/file" "ext3" :: AbsPath/dir/file.ext3>>>replaceExtensions "." "ext" :: RelPath.>>>replaceExtensions "/" "ext" :: AbsPath/
replaceExtensionss :: Path rel -> [Extension] -> Path rel Source #
Replace all the extensions of a path with the given list of extensions
>>>replaceExtensionss "dir/file.ext1.ext2" ["ext3", "ext4"] :: RelPathdir/file.ext3.ext4>>>replaceExtensionss "dir/file.ext1" ["ext3", "ext4"] :: RelPathdir/file.ext3.ext4>>>replaceExtensionss "dir/file" ["ext3", "ext4"] :: RelPathdir/file.ext3.ext4>>>replaceExtensionss "/dir/file.ext1.ext2" ["ext3", "ext4"] :: AbsPath/dir/file.ext3.ext4>>>replaceExtensionss "/dir/file.ext1" ["ext3", "ext4"] :: AbsPath/dir/file.ext3.ext4>>>replaceExtensionss "/dir/file" ["ext3", "ext4"] :: AbsPath/dir/file.ext3.ext4>>>replaceExtensionss "." ["ext1", "ext2"] :: RelPath.>>>replaceExtensionss "/" ["ext1", "ext2"] :: AbsPath/
Removing given extensions
stripExtension :: Path rel -> Extension -> Maybe (Path rel) Source #
Drop the given extension from a FilePath. Fails if the FilePath does not have the given extension.
>>>stripExtension "foo.x.hs.o" "o" :: Maybe RelPathJust foo.x.hs>>>stripExtension "foo.x.hs.o" "hs" :: Maybe RelPathNothing>>>stripExtension "a.b.c.d" "d" :: Maybe RelPathJust a.b.c>>>stripExtension "foo.bar" "baz" :: Maybe RelPathNothing>>>stripExtension "foobar" "bar" :: Maybe RelPathNothing
Replaces System.FilePath.stripExtension
stripExtensions :: Path rel -> [Extension] -> Maybe (Path rel) Source #
Drop the given extensions from a FilePath. Fails if the FilePath does not have all of the given extensions.
>>>stripExtensions "foo.x.hs.o" ["hs", "o"] :: Maybe RelPathJust foo.x>>>stripExtensions "foo.x.hs.o" ["o", "hs"] :: Maybe RelPathNothing>>>stripExtensions "a.b.c.d" ["c", "d"] :: Maybe RelPathJust a.b>>>stripExtensions "foo.bar" ["baz", "quux"] :: Maybe RelPathNothing>>>stripExtensions "foobar" ["bar"] :: Maybe RelPathNothing
Splitting extensions off a path
splitExtension :: Path rel -> Maybe (Path rel, Extension) Source #
Split off the extensions from a path
>>>splitExtension ("dir/file.ext1.ext2" :: RelPath)Just (dir/file.ext1,ext2)>>>splitExtension ("dir/file.ext" :: RelPath)Just (dir/file,ext)>>>splitExtension ("dir/file" :: RelPath)Nothing>>>splitExtension ("/dir/file.ext1.ext2" :: AbsPath)Just (/dir/file.ext1,ext2)>>>splitExtension ("/dir/file.ext" :: AbsPath)Just (/dir/file,ext)>>>splitExtension ("/dir/file" :: AbsPath)Nothing>>>splitExtension ("." :: RelPath)Nothing>>>splitExtension ("/" :: AbsPath)Nothing
Replaces System.FilePath.splitExtension
splitExtensions :: Path rel -> (Path rel, [Extension]) Source #
Split off the extensions from a path
>>>splitExtensions ("dir/file.ext1.ext2" :: RelPath)(dir/file,[ext1,ext2])>>>splitExtensions ("dir/file.ext" :: RelPath)(dir/file,[ext])>>>splitExtensions ("dir/file" :: RelPath)(dir/file,[])>>>splitExtensions ("/dir/file.ext1.ext2" :: AbsPath)(/dir/file,[ext1,ext2])>>>splitExtensions ("/dir/file.ext" :: AbsPath)(/dir/file,[ext])>>>splitExtensions ("/dir/file" :: AbsPath)(/dir/file,[])>>>splitExtensions ("." :: RelPath)(.,[])>>>splitExtensions ("/" :: AbsPath)(/,[])
Predicates involving extensions
hasExtension :: Path rel -> Bool Source #
Check whether the given filepath has any extensions
>>>hasExtension ("/directory/path.ext" :: AbsPath)True>>>hasExtension ("/directory/path" :: AbsPath)False
Replaces System.FilePath.hasExtension
Functions involving Path pieces
File names
Inspecting file names
takeFileNameExact :: Path rel -> Maybe RelPath Source #
Take the last piece and the extensions, exactly.
This will evaluate to Nothing if the given path is empty
>>>takeFileNameExact ("/directory/file.ext" :: AbsPath)Just file.ext>>>takeFileNameExact ("file/bob.txt" :: RelPath)Just bob.txt>>>takeFileNameExact ("file" :: RelPath)Just file>>>takeFileNameExact ("dir.ext/file.ext" :: RelPath)Just file.ext>>>takeFileNameExact ("." :: RelPath)Nothing>>>takeFileNameExact ("/" :: AbsPath)Nothing
Replaces System.FilePath.takeFileName
takeFileName :: Path rel -> RelPath Source #
Take the last piece and the extensions.
This will evaluate to the empty (relative) path if the given path is empty.
>>>takeFileName ("/directory/file.ext" :: AbsPath)file.ext>>>takeFileName ("file/bob.txt" :: RelPath)bob.txt>>>takeFileName ("file" :: RelPath)file>>>takeFileName ("dir.ext/file.ext" :: RelPath)file.ext>>>takeFileName ("." :: RelPath).>>>takeFileName ("/" :: AbsPath).
Replaces System.FilePath.takeFileName
Removing file names
dropFileNameExact :: Path rel -> Maybe (Path rel) Source #
Drop the last piece of a path, exactly
>>>dropFileNameExact ("directory/file.ext" :: RelPath)Just directory>>>dropFileNameExact ("/directory/file.ext" :: AbsPath)Just /directory
This evaluates to Nothing when given an empty path
>>>dropFileNameExact ("/" :: AbsPath)Nothing>>>dropFileNameExact ("." :: RelPath)Nothing
dropFileName :: Path rel -> Path rel Source #
Drop the last piece of a path
>>>dropFileName ("directory/file.ext" :: RelPath)directory>>>dropFileName ("/directory/file.ext" :: AbsPath)/directory
This evaluates to an empty path when given an empty path
>>>dropFileName ("/" :: AbsPath)/>>>dropFileName ("." :: RelPath).
Replaces System.FilePath.dropFileName and System.FilePath.takeDirectory
Replacing file names
replaceFileNameExact :: Path rel -> PathPiece -> Maybe (Path rel) Source #
Replace the last piece of a path with the given last piece.
>>>replaceFileNameExact "/directory/other.txt" "file.ext" :: Maybe AbsPathJust /directory/file.ext>>>replaceFileNameExact "." "file.ext" :: Maybe RelPathJust file.ext>>>replaceFileNameExact "/" "file.ext" :: Maybe AbsPathJust /file.ext
If the given path piece is degenerate, this is what happens:
>>>replaceFileNameExact "/directory/other.txt" "..." :: Maybe AbsPathNothing
replaceFileName :: Path rel -> PathPiece -> Path rel Source #
Replace the last piece of a path with the given last piece.
>>>replaceFileName "/directory/other.txt" "file.ext" :: AbsPath/directory/file.ext>>>replaceFileName "." "file.ext" :: RelPathfile.ext>>>replaceFileName "/" "file.ext" :: AbsPath/file.ext
If the given path piece is degenerate, this is what happens:
>>>replaceFileName "/directory/other.txt" "..." :: AbsPath/directory
Base names
Inspecting base names
takeBaseNameExact :: Path rel -> Maybe LastPathPiece Source #
Take the last piece (no extensions)
>>>takeBaseNameExact ("file.ext" :: RelPath)Just file>>>takeBaseNameExact ("dir/and/file.ext" :: RelPath)Just file
This will evaluate to Nothing when given an empty path:
>>>takeBaseNameExact ("." :: RelPath)Nothing>>>takeBaseNameExact ("/" :: AbsPath)Nothing
takeBaseName :: Path rel -> LastPathPiece Source #
Take the last piece (no extensions)
>>>takeBaseName ("file.ext" :: RelPath)file>>>takeBaseName ("dir/and/file.ext" :: RelPath)file
This will evaluate to an empty last path piece when given an empty path:
Replaces System.FilePath.takeBaseName
Replacing base names
replaceBaseNameExact :: Path rel -> LastPathPiece -> Maybe (Path rel) Source #
Replace the last piece exactly: fails on empty last piece
>>>replaceBaseNameExact "file.ext" "piece" :: Maybe RelPathJust piece.ext>>>replaceBaseNameExact "." "thing" :: Maybe RelPathJust thing>>>replaceBaseNameExact "/" "thing" :: Maybe AbsPathJust /thing>>>replaceBaseNameExact "/directory/file" "" :: Maybe AbsPathNothing
replaceBaseName :: Path rel -> LastPathPiece -> Path rel Source #
Replace the last piece
>>>replaceBaseName "file.ext" "piece" :: RelPathpiece.ext>>>replaceBaseName "." "thing" :: RelPaththing>>>replaceBaseName "/" "thing" :: AbsPath/thing>>>replaceBaseName "/directory/file" "" :: AbsPath/directory
Replaces System.FilePath.replaceBaseName
Directories
Replacing directories
replaceDirectoryExact :: Path r -> Path s -> Maybe (Path s) Source #
Replace everthing but the last piece, exactly
>>>replaceDirectoryExact ("/dir/and/file" :: AbsPath) ("other/directory" :: RelPath)Just other/directory/file
This will evaluate to Nothing if the first argument is an empty path.
>>>replaceDirectoryExact ("." :: RelPath) ("a/directory" :: RelPath)Nothing>>>replaceDirectoryExact ("/" :: AbsPath) ("a/directory" :: RelPath)Nothing
This will evaluate to Nothing if the second argument is an empty path.
>>>replaceDirectoryExact ("dir/file" :: RelPath) ("." :: RelPath)Nothing>>>replaceDirectoryExact ("dir/file" :: RelPath) ("/" :: AbsPath)Nothing
replaceDirectory :: Path r -> Path s -> Path s Source #
Replace everthing but the last piece
>>>replaceDirectory ("/dir/and/file" :: AbsPath) ("other/directory" :: RelPath)other/directory/file>>>replaceDirectory ("." :: RelPath) ("a/directory" :: RelPath)a/directory>>>replaceDirectory ("/" :: AbsPath) ("a/directory" :: RelPath)a/directory>>>replaceDirectory ("dir/file" :: RelPath) ("." :: RelPath)file>>>replaceDirectory ("dir/file" :: RelPath) ("/" :: AbsPath)/file
Replaces System.FilePath.replaceDirectory
Combining paths
combineExact :: Path rel -> RelPath -> Maybe (Path rel) Source #
Combine two paths, exactly
If the first path has extensions, they will be appended to the last pathpiece before concatenation
>>>combineExact "/directory/path" "another/path.ext" :: Maybe AbsPathJust /directory/path/another/path.ext>>>combineExact "directory/path" "another/path.ext" :: Maybe RelPathJust directory/path/another/path.ext>>>combineExact "/file.ext1.ext2" "other/file.ext3" :: Maybe AbsPathJust /file.ext1.ext2/other/file.ext3>>>combineExact "file.ext1.ext2" "other/file.ext3" :: Maybe RelPathJust file.ext1.ext2/other/file.ext3
This evaluates to Nothing if any of the given paths are empty
>>>combineExact "." "file.ext" :: Maybe RelPathNothing>>>combineExact "/" "file.ext" :: Maybe AbsPathNothing
combine :: Path rel -> RelPath -> Path rel Source #
Combine two paths
If the first path has extensions, they will be appended to the last pathpiece before concatenation
>>>combine "/directory/path" "another/path.ext" :: AbsPath/directory/path/another/path.ext>>>combine "directory/path" "another/path.ext" :: RelPathdirectory/path/another/path.ext>>>combine "/file.ext1.ext2" "other/file.ext3" :: AbsPath/file.ext1.ext2/other/file.ext3>>>combine "file.ext1.ext2" "other/file.ext3" :: RelPathfile.ext1.ext2/other/file.ext3
This treats empty paths as identities to the operation.
>>>combine "file.ext" "." :: RelPathfile.ext>>>combine "." "file.ext" :: RelPathfile.ext>>>combine "/" "file.ext" :: AbsPath/file.ext>>>combine "." "." :: RelPath.>>>combine "/" "." :: AbsPath/
Replaces System.FilePath.combine
(</>) :: Path rel -> RelPath -> Path rel Source #
Combine two paths
equivalent to combine
>>>"/directory/path" </> "another/path.ext" :: AbsPath/directory/path/another/path.ext>>>"directory/path" </> "another/path.ext" :: RelPathdirectory/path/another/path.ext>>>"/file.ext1.ext2" </> "other/file.ext3" :: AbsPath/file.ext1.ext2/other/file.ext3>>>"file.ext1.ext2" </> "other/file.ext3" :: RelPathfile.ext1.ext2/other/file.ext3>>>"." </> "file.ext" :: RelPathfile.ext>>>"/" </> "file.ext" :: AbsPath/file.ext
Replaces System.FilePath.(/)
Pieces of paths
splitPath :: Path rel -> [PathPiece] Source #
Split a path up into pieces
>>>splitPath ("/a/full/absolute/directory/path" :: AbsPath)[a,full,absolute,directory,path]
joinPath :: [PathPiece] -> Maybe (Path rel) Source #
Join path pieces back into a path
>>>joinPath ["a", "full", "absolute", "directory", "path"] :: Maybe AbsPathJust /a/full/absolute/directory/path>>>joinPath [] :: Maybe RelPathJust .>>>joinPath [] :: Maybe AbsPathJust />>>joinPath [".", "."] :: Maybe RelPathNothing
Separators
Paths
pathSeparator :: Char Source #
pathSeparators :: [Char] Source #
isPathSeparator :: Char -> Bool Source #
Check if a given character is a valid path separator
>>>isPathSeparator pathSeparatorTrue>>>all isPathSeparator pathSeparatorsTrue
Extension
extensionSeparators :: [Char] Source #
isExtensionSeparator :: Char -> Bool Source #
Check if a given character is a valid extension separator
>>>isExtensionSeparator extensionSeparatorTrue>>>all isExtensionSeparator extensionSeparatorsTrue