Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
The equivalent of System.FilePath on raw (byte string) file paths.
Not all functions of System.FilePath are implemented yet. Feel free to contribute!
- pathSeparator :: Word8
- isPathSeparator :: Word8 -> Bool
- searchPathSeparator :: Word8
- isSearchPathSeparator :: Word8 -> Bool
- extSeparator :: Word8
- isExtSeparator :: Word8 -> Bool
- splitExtension :: RawFilePath -> (RawFilePath, ByteString)
- takeExtension :: RawFilePath -> ByteString
- replaceExtension :: RawFilePath -> ByteString -> RawFilePath
- dropExtension :: RawFilePath -> RawFilePath
- addExtension :: RawFilePath -> ByteString -> RawFilePath
- hasExtension :: RawFilePath -> Bool
- (<.>) :: RawFilePath -> ByteString -> RawFilePath
- splitExtensions :: RawFilePath -> (RawFilePath, ByteString)
- dropExtensions :: RawFilePath -> RawFilePath
- takeExtensions :: RawFilePath -> ByteString
- splitFileName :: RawFilePath -> (RawFilePath, RawFilePath)
- takeFileName :: RawFilePath -> RawFilePath
- replaceFileName :: RawFilePath -> ByteString -> RawFilePath
- dropFileName :: RawFilePath -> RawFilePath
- takeBaseName :: RawFilePath -> ByteString
- replaceBaseName :: RawFilePath -> ByteString -> RawFilePath
- takeDirectory :: RawFilePath -> RawFilePath
- replaceDirectory :: RawFilePath -> ByteString -> RawFilePath
- combine :: RawFilePath -> RawFilePath -> RawFilePath
- (</>) :: RawFilePath -> RawFilePath -> RawFilePath
- splitPath :: RawFilePath -> [RawFilePath]
- joinPath :: [RawFilePath] -> RawFilePath
- splitDirectories :: RawFilePath -> [RawFilePath]
- hasTrailingPathSeparator :: RawFilePath -> Bool
- addTrailingPathSeparator :: RawFilePath -> RawFilePath
- dropTrailingPathSeparator :: RawFilePath -> RawFilePath
- isRelative :: RawFilePath -> Bool
- isAbsolute :: RawFilePath -> Bool
- module System.Posix.ByteString.FilePath
Documentation
pathSeparator :: Word8 Source #
Path separator character
isPathSeparator :: Word8 -> Bool Source #
Check if a character is the path separator
\n -> (_chr n == '/') == isPathSeparator n
searchPathSeparator :: Word8 Source #
Search path separator
isSearchPathSeparator :: Word8 -> Bool Source #
Check if a character is the search path separator
\n -> (_chr n == ':') == isSearchPathSeparator n
extSeparator :: Word8 Source #
File extension separator
isExtSeparator :: Word8 -> Bool Source #
Check if a character is the file extension separator
\n -> (_chr n == '.') == isExtSeparator n
splitExtension :: RawFilePath -> (RawFilePath, ByteString) Source #
Split a RawFilePath
into a path+filename and extension
>>>
splitExtension "file.exe"
("file",".exe")
>>>
splitExtension "file"
("file","")
>>>
splitExtension "/path/file.tar.gz"
("/path/file.tar",".gz")
\path -> uncurry (BS.append) (splitExtension path) == path
takeExtension :: RawFilePath -> ByteString Source #
Get the final extension from a RawFilePath
>>>
takeExtension "file.exe"
".exe"
>>>
takeExtension "file"
""
>>>
takeExtension "/path/file.tar.gz"
".gz"
replaceExtension :: RawFilePath -> ByteString -> RawFilePath Source #
Change a file's extension
\path -> let ext = takeExtension path in replaceExtension path ext == path
dropExtension :: RawFilePath -> RawFilePath Source #
Drop the final extension from a RawFilePath
>>>
dropExtension "file.exe"
"file"
>>>
dropExtension "file"
"file"
>>>
dropExtension "/path/file.tar.gz"
"/path/file.tar"
addExtension :: RawFilePath -> ByteString -> RawFilePath Source #
Add an extension to a RawFilePath
>>>
addExtension "file" ".exe"
"file.exe"
>>>
addExtension "file.tar" ".gz"
"file.tar.gz"
>>>
addExtension "/path/" ".ext"
"/path/.ext"
hasExtension :: RawFilePath -> Bool Source #
Check if a RawFilePath
has an extension
>>>
hasExtension "file"
False
>>>
hasExtension "file.tar"
True
>>>
hasExtension "/path.part1/"
False
(<.>) :: RawFilePath -> ByteString -> RawFilePath Source #
Operator version of addExtension
splitExtensions :: RawFilePath -> (RawFilePath, ByteString) Source #
Split a RawFilePath
on the first extension
>>>
splitExtensions "/path/file.tar.gz"
("/path/file",".tar.gz")
\path -> uncurry addExtension (splitExtensions path) == path
dropExtensions :: RawFilePath -> RawFilePath Source #
Remove all extensions from a RawFilePath
>>>
dropExtensions "/path/file.tar.gz"
"/path/file"
takeExtensions :: RawFilePath -> ByteString Source #
Take all extensions from a RawFilePath
>>>
takeExtensions "/path/file.tar.gz"
".tar.gz"
splitFileName :: RawFilePath -> (RawFilePath, RawFilePath) Source #
Split a RawFilePath
into (path,file). combine
is the inverse
>>>
splitFileName "path/file.txt"
("path/","file.txt")
>>>
splitFileName "path/"
("path/","")
>>>
splitFileName "file.txt"
("./","file.txt")
\path -> uncurry combine (splitFileName path) == path || fst (splitFileName path) == "./"
takeFileName :: RawFilePath -> RawFilePath Source #
Get the file name
>>>
takeFileName "path/file.txt"
"file.txt"
>>>
takeFileName "path/"
""
replaceFileName :: RawFilePath -> ByteString -> RawFilePath Source #
Change the file name
\path -> replaceFileName path (takeFileName path) == path
dropFileName :: RawFilePath -> RawFilePath Source #
Drop the file name
>>>
dropFileName "path/file.txt"
"path/"
>>>
dropFileName "file.txt"
"./"
takeBaseName :: RawFilePath -> ByteString Source #
Get the file name, without a trailing extension
>>>
takeBaseName "path/file.tar.gz"
"file.tar"
>>>
takeBaseName ""
""
replaceBaseName :: RawFilePath -> ByteString -> RawFilePath Source #
Change the base name
>>>
replaceBaseName "path/file.tar.gz" "bob"
"path/bob.gz"
\path -> replaceBaseName path (takeBaseName path) == path
takeDirectory :: RawFilePath -> RawFilePath Source #
Get the directory, moving up one level if it's already a directory
>>>
takeDirectory "path/file.txt"
"path"
>>>
takeDirectory "file"
"."
>>>
takeDirectory "/path/to/"
"/path/to"
>>>
takeDirectory "/path/to"
"/path"
replaceDirectory :: RawFilePath -> ByteString -> RawFilePath Source #
Change the directory component of a RawFilePath
\path -> replaceDirectory path (takeDirectory path) `_equalFilePath` path || takeDirectory path == "."
combine :: RawFilePath -> RawFilePath -> RawFilePath Source #
Join two paths together
>>>
combine "/" "file"
"/file">>>
combine "/path/to" "file"
"/path/to/file">>>
combine "file" "/absolute/path"
"/absolute/path"
(</>) :: RawFilePath -> RawFilePath -> RawFilePath Source #
Operator version of combine
splitPath :: RawFilePath -> [RawFilePath] Source #
Split a path into a list of components:
>>>
splitPath "/path/to/file.txt"
["/","path/","to/","file.txt"]
\path -> BS.concat (splitPath path) == path
joinPath :: [RawFilePath] -> RawFilePath Source #
Join a split path back together
\path -> joinPath (splitPath path) == path
>>>
joinPath ["path","to","file.txt"]
"path/to/file.txt"
splitDirectories :: RawFilePath -> [RawFilePath] Source #
Like splitPath
, but without trailing slashes
>>>
splitDirectories "/path/to/file.txt"
["/","path","to","file.txt"]>>>
splitDirectories ""
[]
hasTrailingPathSeparator :: RawFilePath -> Bool Source #
Check if the last character of a RawFilePath
is /
, unless it's the
root.
>>>
hasTrailingPathSeparator "/path/"
True>>>
hasTrailingPathSeparator "/"
False
addTrailingPathSeparator :: RawFilePath -> RawFilePath Source #
Add a trailing path separator.
>>>
addTrailingPathSeparator "/path"
"/path/"
>>>
addTrailingPathSeparator "/path/"
"/path/"
dropTrailingPathSeparator :: RawFilePath -> RawFilePath Source #
Remove a trailing path separator
>>>
dropTrailingPathSeparator "/path/"
"/path"
>>>
dropTrailingPathSeparator "/"
"/"
isRelative :: RawFilePath -> Bool Source #
Check if a path is relative
\path -> isRelative path /= isAbsolute path
isAbsolute :: RawFilePath -> Bool Source #
Check if a path is absolute
>>>
isAbsolute "/path"
True>>>
isAbsolute "path"
False>>>
isAbsolute ""
False