243 lines
45 KiB
HTML
243 lines
45 KiB
HTML
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>System.Posix.FilePath</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script><script type="text/javascript">//<![CDATA[
|
||
|
window.onload = function () {pageLoad();setSynopsis("mini_System-Posix-FilePath.html");};
|
||
|
//]]>
|
||
|
</script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="src/System-Posix-FilePath.html">Source</a></li><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">hpath-0.7.3: Support for well-typed paths</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Copyright</th><td>© 2016 Julian Ospald</td></tr><tr><th>License</th><td>BSD3</td></tr><tr><th>Maintainer</th><td>Julian Ospald <hasufell@posteo.de></td></tr><tr><th>Stability</th><td>experimental</td></tr><tr><th>Portability</th><td>portable</td></tr><tr><th>Safe Haskell</th><td>Safe</td></tr><tr><th>Language</th><td>Haskell2010</td></tr></table><p class="caption">System.Posix.FilePath</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">Separator predicates</a></li><li><a href="#g:2">$PATH methods</a></li><li><a href="#g:3">Extension functions</a></li><li><a href="#g:4">Filename/directory functions</a></li><li><a href="#g:5">Trailing slash functions</a></li><li><a href="#g:6">File name manipulations</a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>The equivalent of <a href="System-FilePath.html">System.FilePath</a> on raw (byte string) file paths.</p><p>Not all functions of <a href="System-FilePath.html">System.FilePath</a> are implemented yet. Feel free to contribute!</p></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><a href="#v:pathSeparator">pathSeparator</a> :: Word8</li><li class="src short"><a href="#v:isPathSeparator">isPathSeparator</a> :: Word8 -> Bool</li><li class="src short"><a href="#v:searchPathSeparator">searchPathSeparator</a> :: Word8</li><li class="src short"><a href="#v:isSearchPathSeparator">isSearchPathSeparator</a> :: Word8 -> Bool</li><li class="src short"><a href="#v:extSeparator">extSeparator</a> :: Word8</li><li class="src short"><a href="#v:isExtSeparator">isExtSeparator</a> :: Word8 -> Bool</li><li class="src short"><a href="#v:splitSearchPath">splitSearchPath</a> :: <a href="https://hackage.haskell.org/package/utf8-string-0.3.7/docs/Data-ByteString-UTF8.html#t:ByteString">ByteString</a> -> [RawFilePath]</li><li class="src short"><a href="#v:getSearchPath">getSearchPath</a> :: IO [RawFilePath]</li><li class="src short"><a href="#v:splitExtension">splitExtension</a> :: RawFilePath -> (RawFilePath, <a href="https://hackage.haskell.org/package/utf8-string-0.3.7/docs/Data-ByteString-UTF8.html#t:ByteString">ByteString</a>)</li><li class="src short"><a href="#v:takeExtension">takeExtension</a> :: RawFilePath -> <a href="https://hackage.haskell.org/package/utf8-string-0.3.7/docs/Data-ByteString-UTF8.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:replaceExtension">replaceExtension</a> :: RawFilePath -> <a href="https://hackage.haskell.org/package/utf8-string-0.3.7/docs/Data-ByteString-UTF8.html#t:ByteString">ByteString</a> -> RawFilePath</li><li class="src short"><a href="#v:dropExtension">dropExtension</a> :: RawFilePath -> RawFilePath</li><li class="src short"><a href="#v:addExtension">addExtension</a> :: RawFilePath -> <a href="https://hackage.haskell.org/package/utf8-string-0.3.7/docs/Data-ByteString-UTF8.html#t:ByteString">ByteString</a> -> RawFilePath</li><li class="src short"><a href="#v:hasExtension">hasExtension</a> :: RawFilePath -> Bool</li><li class="src short"><a href="#v:-60-.-62-">(<.>)</a> :: RawFilePath -> <a href="https://hackage.haskell.org/package/utf8-string-0.3.7/docs/Data-ByteString-UTF8.html#t:ByteString">ByteString</a> -> RawFilePath</li><li class="src short"><a href="#v:splitExtensions">splitExtensions</a> :: RawFilePath -> (RawFilePath, <a href="https://hackage.haskell.org/package/utf8-string-0.3.7/docs/Data-ByteString-UTF8.html#t:ByteString">ByteString</a>)</li><li class="src short"><a
|
||
|
Blank items are converted to <code>.</code>.</p><p>Follows the recommendations in
|
||
|
<a href="http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html">http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html</a></p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>splitSearchPath "File1:File2:File3"
|
||
|
</code></strong>["File1","File2","File3"]
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>splitSearchPath "File1::File2:File3"
|
||
|
</code></strong>["File1",".","File2","File3"]
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>splitSearchPath ""
|
||
|
</code></strong>["."]
|
||
|
</pre></div></div><div class="top"><p class="src"><a id="v:getSearchPath" class="def">getSearchPath</a> :: IO [RawFilePath] <a href="src/System-Posix-FilePath.html#getSearchPath" class="link">Source</a> <a href="#v:getSearchPath" class="selflink">#</a></p><div class="doc"><p>Get a list of <code>RawFilePath</code>s in the $PATH variable.</p></div></div><h1 id="g:3">Extension functions</h1><div class="top"><p class="src"><a id="v:splitExtension" class="def">splitExtension</a> :: RawFilePath -> (RawFilePath, <a href="https://hackage.haskell.org/package/utf8-string-0.3.7/docs/Data-ByteString-UTF8.html#t:ByteString">ByteString</a>) <a href="src/System-Posix-FilePath.html#splitExtension" class="link">Source</a> <a href="#v:splitExtension" class="selflink">#</a></p><div class="doc"><p>Split a <code>RawFilePath</code> into a path+filename and extension</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>splitExtension "file.exe"
|
||
|
</code></strong>("file",".exe")
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>splitExtension "file"
|
||
|
</code></strong>("file","")
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>splitExtension "/path/file.tar.gz"
|
||
|
</code></strong>("/path/file.tar",".gz")
|
||
|
</pre><pre>\path -> uncurry (BS.append) (splitExtension path) == path</pre></div></div><div class="top"><p class="src"><a id="v:takeExtension" class="def">takeExtension</a> :: RawFilePath -> <a href="https://hackage.haskell.org/package/utf8-string-0.3.7/docs/Data-ByteString-UTF8.html#t:ByteString">ByteString</a> <a href="src/System-Posix-FilePath.html#takeExtension" class="link">Source</a> <a href="#v:takeExtension" class="selflink">#</a></p><div class="doc"><p>Get the final extension from a <code>RawFilePath</code></p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>takeExtension "file.exe"
|
||
|
</code></strong>".exe"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>takeExtension "file"
|
||
|
</code></strong>""
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>takeExtension "/path/file.tar.gz"
|
||
|
</code></strong>".gz"
|
||
|
</pre></div></div><div class="top"><p class="src"><a id="v:replaceExtension" class="def">replaceExtension</a> :: RawFilePath -> <a href="https://hackage.haskell.org/package/utf8-string-0.3.7/docs/Data-ByteString-UTF8.html#t:ByteString">ByteString</a> -> RawFilePath <a href="src/System-Posix-FilePath.html#replaceExtension" class="link">Source</a> <a href="#v:replaceExtension" class="selflink">#</a></p><div class="doc"><p>Change a file's extension</p><pre>\path -> let ext = takeExtension path in replaceExtension path ext == path</pre></div></div><div class="top"><p class="src"><a id="v:dropExtension" class="def">dropExtension</a> :: RawFilePath -> RawFilePath <a href="src/System-Posix-FilePath.html#dropExtension" class="link">Source</a> <a href="#v:dropExtension" class="selflink">#</a></p><div class="doc"><p>Drop the final extension from a <code>RawFilePath</code></p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>dropExtension "file.exe"
|
||
|
</code></strong>"file"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>dropExtension "file"
|
||
|
</code></strong>"file"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>dropExtension "/path/file.tar.gz"
|
||
|
</code></strong>"/path/file.tar"
|
||
|
</pre></div></div><div class="top"><p class="src"><a id="v:addExtension" class="def">addExtension</a> :: RawFilePath -> <a href="https://hackage.haskell.org/package/utf8-string-0.3.7/docs/Data-ByteString-UTF8.html#t:ByteString">ByteString</a> -> RawFilePath <a href="src/System-Posix-FilePath.html#addExtension" class="link">Source</a> <a href="#v:addExtension" class="selflink">#</a></p><div class="doc"><p>Add an extension to a <code>RawFilePath</code></p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>addExtension "file" ".exe"
|
||
|
</code></strong>"file.exe"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>addExtension "file.tar" ".gz"
|
||
|
</code></strong>"file.tar.gz"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>addExtension "/path/" ".ext"
|
||
|
</code></strong>"/path/.ext"
|
||
|
</pre></div></div><div class="top"><p class="src"><a id="v:hasExtension" class="def">hasExtension</a> :: RawFilePath -> Bool <a href="src/System-Posix-FilePath.html#hasExtension" class="link">Source</a> <a href="#v:hasExtension" class="selflink">#</a></p><div class="doc"><p>Check if a <code>RawFilePath</code> has an extension</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>hasExtension "file"
|
||
|
</code></strong>False
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>hasExtension "file.tar"
|
||
|
</code></strong>True
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>hasExtension "/path.part1/"
|
||
|
</code></strong>False
|
||
|
</pre></div></div><div class="top"><p class="src"><a id="v:-60-.-62-" class="def">(<.>)</a> :: RawFilePath -> <a href="https://hackage.haskell.org/package/utf8-string-0.3.7/docs/Data-ByteString-UTF8.html#t:ByteString">ByteString</a> -> RawFilePath <a href="src/System-Posix-FilePath.html#%3C.%3E" class="link">Source</a> <a href="#v:-60-.-62-" class="selflink">#</a></p><div class="doc"><p>Operator version of <code><a href="System-Posix-FilePath.html#v:addExtension">addExtension</a></code></p></div></div><div class="top"><p class="src"><a id="v:splitExtensions" class="def">splitExtensions</a> :: RawFilePath -> (RawFilePath, <a href="https://hackage.haskell.org/package/utf8-string-0.3.7/docs/Data-ByteString-UTF8.html#t:ByteString">ByteString</a>) <a href="src/System-Posix-FilePath.html#splitExtensions" class="link">Source</a> <a href="#v:splitExtensions" class="selflink">#</a></p><div class="doc"><p>Split a <code>RawFilePath</code> on the first extension.</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>splitExtensions "/path/file.tar.gz"
|
||
|
</code></strong>("/path/file",".tar.gz")
|
||
|
</pre><pre>\path -> uncurry addExtension (splitExtensions path) == path</pre></div></div><div class="top"><p class="src"><a id="v:dropExtensions" class="def">dropExtensions</a> :: RawFilePath -> RawFilePath <a href="src/System-Posix-FilePath.html#dropExtensions" class="link">Source</a> <a href="#v:dropExtensions" class="selflink">#</a></p><div class="doc"><p>Remove all extensions from a <code>RawFilePath</code></p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>dropExtensions "/path/file.tar.gz"
|
||
|
</code></strong>"/path/file"
|
||
|
</pre></div></div><div class="top"><p class="src"><a id="v:takeExtensions" class="def">takeExtensions</a> :: RawFilePath -> <a href="https://hackage.haskell.org/package/utf8-string-0.3.7/docs/Data-ByteString-UTF8.html#t:ByteString">ByteString</a> <a href="src/System-Posix-FilePath.html#takeExtensions" class="link">Source</a> <a href="#v:takeExtensions" class="selflink">#</a></p><div class="doc"><p>Take all extensions from a <code>RawFilePath</code></p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>takeExtensions "/path/file.tar.gz"
|
||
|
</code></strong>".tar.gz"
|
||
|
</pre></div></div><div class="top"><p class="src"><a id="v:stripExtension" class="def">stripExtension</a> :: <a href="https://hackage.haskell.org/package/utf8-string-0.3.7/docs/Data-ByteString-UTF8.html#t:ByteString">ByteString</a> -> RawFilePath -> Maybe RawFilePath <a href="src/System-Posix-FilePath.html#stripExtension" class="link">Source</a> <a href="#v:stripExtension" class="selflink">#</a></p><div class="doc"><p>Drop the given extension from a FilePath, and the <code>"."</code> preceding it.
|
||
|
Returns <code>Nothing</code> if the FilePath does not have the given extension, or
|
||
|
<code>Just</code> and the part before the extension if it does.</p><p>This function can be more predictable than <code><a href="System-Posix-FilePath.html#v:dropExtensions">dropExtensions</a></code>,
|
||
|
especially if the filename might itself contain <code>.</code> characters.</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>stripExtension "hs.o" "foo.x.hs.o"
|
||
|
</code></strong>Just "foo.x"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>stripExtension "hi.o" "foo.x.hs.o"
|
||
|
</code></strong>Nothing
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>stripExtension ".c.d" "a.b.c.d"
|
||
|
</code></strong>Just "a.b"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>stripExtension ".c.d" "a.b..c.d"
|
||
|
</code></strong>Just "a.b."
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>stripExtension "baz" "foo.bar"
|
||
|
</code></strong>Nothing
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>stripExtension "bar" "foobar"
|
||
|
</code></strong>Nothing
|
||
|
</pre><pre>\path -> stripExtension "" path == Just path</pre><pre>\path -> dropExtension path == fromJust (stripExtension (takeExtension path) path)</pre><pre>\path -> dropExtensions path == fromJust (stripExtension (takeExtensions path) path)</pre></div></div><h1 id="g:4">Filename/directory functions</h1><div class="top"><p class="src"><a id="v:splitFileName" class="def">splitFileName</a> :: RawFilePath -> (RawFilePath, RawFilePath) <a href="src/System-Posix-FilePath.html#splitFileName" class="link">Source</a> <a href="#v:splitFileName" class="selflink">#</a></p><div class="doc"><p>Split a <code>RawFilePath</code> into (path,file). <code><a href="System-Posix-FilePath.html#v:combine">combine</a></code> is the inverse</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>splitFileName "path/file.txt"
|
||
|
</code></strong>("path/","file.txt")
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>splitFileName "path/"
|
||
|
</code></strong>("path/","")
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>splitFileName "file.txt"
|
||
|
</code></strong>("./","file.txt")
|
||
|
</pre><pre>\path -> uncurry combine (splitFileName path) == path || fst (splitFileName path) == "./"</pre></div></div><div class="top"><p class="src"><a id="v:takeFileName" class="def">takeFileName</a> :: RawFilePath -> RawFilePath <a href="src/System-Posix-FilePath.html#takeFileName" class="link">Source</a> <a href="#v:takeFileName" class="selflink">#</a></p><div class="doc"><p>Get the file name</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>takeFileName "path/file.txt"
|
||
|
</code></strong>"file.txt"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>takeFileName "path/"
|
||
|
</code></strong>""
|
||
|
</pre></div></div><div class="top"><p class="src"><a id="v:replaceFileName" class="def">replaceFileName</a> :: RawFilePath -> <a href="https://hackage.haskell.org/package/utf8-string-0.3.7/docs/Data-ByteString-UTF8.html#t:ByteString">ByteString</a> -> RawFilePath <a href="src/System-Posix-FilePath.html#replaceFileName" class="link">Source</a> <a href="#v:replaceFileName" class="selflink">#</a></p><div class="doc"><p>Change the file name</p><pre>\path -> replaceFileName path (takeFileName path) == path</pre></div></div><div class="top"><p class="src"><a id="v:dropFileName" class="def">dropFileName</a> :: RawFilePath -> RawFilePath <a href="src/System-Posix-FilePath.html#dropFileName" class="link">Source</a> <a href="#v:dropFileName" class="selflink">#</a></p><div class="doc"><p>Drop the file name</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>dropFileName "path/file.txt"
|
||
|
</code></strong>"path/"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>dropFileName "file.txt"
|
||
|
</code></strong>"./"
|
||
|
</pre></div></div><div class="top"><p class="src"><a id="v:takeBaseName" class="def">takeBaseName</a> :: RawFilePath -> <a href="https://hackage.haskell.org/package/utf8-string-0.3.7/docs/Data-ByteString-UTF8.html#t:ByteString">ByteString</a> <a href="src/System-Posix-FilePath.html#takeBaseName" class="link">Source</a> <a href="#v:takeBaseName" class="selflink">#</a></p><div class="doc"><p>Get the file name, without a trailing extension</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>takeBaseName "path/file.tar.gz"
|
||
|
</code></strong>"file.tar"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>takeBaseName ""
|
||
|
</code></strong>""
|
||
|
</pre></div></div><div class="top"><p class="src"><a id="v:replaceBaseName" class="def">replaceBaseName</a> :: RawFilePath -> <a href="https://hackage.haskell.org/package/utf8-string-0.3.7/docs/Data-ByteString-UTF8.html#t:ByteString">ByteString</a> -> RawFilePath <a href="src/System-Posix-FilePath.html#replaceBaseName" class="link">Source</a> <a href="#v:replaceBaseName" class="selflink">#</a></p><div class="doc"><p>Change the base name</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>replaceBaseName "path/file.tar.gz" "bob"
|
||
|
</code></strong>"path/bob.gz"
|
||
|
</pre><pre>\path -> replaceBaseName path (takeBaseName path) == path</pre></div></div><div class="top"><p class="src"><a id="v:takeDirectory" class="def">takeDirectory</a> :: RawFilePath -> RawFilePath <a href="src/System-Posix-FilePath.html#takeDirectory" class="link">Source</a> <a href="#v:takeDirectory" class="selflink">#</a></p><div class="doc"><p>Get the directory, moving up one level if it's already a directory</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>takeDirectory "path/file.txt"
|
||
|
</code></strong>"path"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>takeDirectory "file"
|
||
|
</code></strong>"."
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>takeDirectory "/path/to/"
|
||
|
</code></strong>"/path/to"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>takeDirectory "/path/to"
|
||
|
</code></strong>"/path"
|
||
|
</pre></div></div><div class="top"><p class="src"><a id="v:replaceDirectory" class="def">replaceDirectory</a> :: RawFilePath -> <a href="https://hackage.haskell.org/package/utf8-string-0.3.7/docs/Data-ByteString-UTF8.html#t:ByteString">ByteString</a> -> RawFilePath <a href="src/System-Posix-FilePath.html#replaceDirectory" class="link">Source</a> <a href="#v:replaceDirectory" class="selflink">#</a></p><div class="doc"><p>Change the directory component of a <code>RawFilePath</code></p><pre>\path -> replaceDirectory path (takeDirectory path) `equalFilePath` path || takeDirectory path == "."</pre></div></div><div class="top"><p class="src"><a id="v:combine" class="def">combine</a> :: RawFilePath -> RawFilePath -> RawFilePath <a href="src/System-Posix-FilePath.html#combine" class="link">Source</a> <a href="#v:combine" class="selflink">#</a></p><div class="doc"><p>Join two paths together</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>combine "/" "file"
|
||
|
</code></strong>"/file"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>combine "/path/to" "file"
|
||
|
</code></strong>"/path/to/file"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>combine "file" "/absolute/path"
|
||
|
</code></strong>"/absolute/path"
|
||
|
</pre></div></div><div class="top"><p class="src"><a id="v:-60--47--62-" class="def">(</>)</a> :: RawFilePath -> RawFilePath -> RawFilePath <a href="src/System-Posix-FilePath.html#%3C%2F%3E" class="link">Source</a> <a href="#v:-60--47--62-" class="selflink">#</a></p><div class="doc"><p>Operator version of combine</p></div></div><div class="top"><p class="src"><a id="v:splitPath" class="def">splitPath</a> :: RawFilePath -> [RawFilePath] <a href="src/System-Posix-FilePath.html#splitPath" class="link">Source</a> <a href="#v:splitPath" class="selflink">#</a></p><div class="doc"><p>Split a path into a list of components:</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>splitPath "/path/to/file.txt"
|
||
|
</code></strong>["/","path/","to/","file.txt"]
|
||
|
</pre><pre>\path -> BS.concat (splitPath path) == path</pre></div></div><div class="top"><p class="src"><a id="v:joinPath" class="def">joinPath</a> :: [RawFilePath] -> RawFilePath <a href="src/System-Posix-FilePath.html#joinPath" class="link">Source</a> <a href="#v:joinPath" class="selflink">#</a></p><div class="doc"><p>Join a split path back together</p><pre>\path -> joinPath (splitPath path) == path</pre><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>joinPath ["path","to","file.txt"]
|
||
|
</code></strong>"path/to/file.txt"
|
||
|
</pre></div></div><div class="top"><p class="src"><a id="v:splitDirectories" class="def">splitDirectories</a> :: RawFilePath -> [RawFilePath] <a href="src/System-Posix-FilePath.html#splitDirectories" class="link">Source</a> <a href="#v:splitDirectories" class="selflink">#</a></p><div class="doc"><p>Like <code><a href="System-Posix-FilePath.html#v:splitPath">splitPath</a></code>, but without trailing slashes</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>splitDirectories "/path/to/file.txt"
|
||
|
</code></strong>["/","path","to","file.txt"]
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>splitDirectories ""
|
||
|
</code></strong>[]
|
||
|
</pre></div></div><h1 id="g:5">Trailing slash functions</h1><div class="top"><p class="src"><a id="v:hasTrailingPathSeparator" class="def">hasTrailingPathSeparator</a> :: RawFilePath -> Bool <a href="src/System-Posix-FilePath.html#hasTrailingPathSeparator" class="link">Source</a> <a href="#v:hasTrailingPathSeparator" class="selflink">#</a></p><div class="doc"><p>Check if the last character of a <code>RawFilePath</code> is <code>/</code>.</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>hasTrailingPathSeparator "/path/"
|
||
|
</code></strong>True
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>hasTrailingPathSeparator "/"
|
||
|
</code></strong>True
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>hasTrailingPathSeparator "/path"
|
||
|
</code></strong>False
|
||
|
</pre></div></div><div class="top"><p class="src"><a id="v:addTrailingPathSeparator" class="def">addTrailingPathSeparator</a> :: RawFilePath -> RawFilePath <a href="src/System-Posix-FilePath.html#addTrailingPathSeparator" class="link">Source</a> <a href="#v:addTrailingPathSeparator" class="selflink">#</a></p><div class="doc"><p>Add a trailing path separator.</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>addTrailingPathSeparator "/path"
|
||
|
</code></strong>"/path/"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>addTrailingPathSeparator "/path/"
|
||
|
</code></strong>"/path/"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>addTrailingPathSeparator "/"
|
||
|
</code></strong>"/"
|
||
|
</pre></div></div><div class="top"><p class="src"><a id="v:dropTrailingPathSeparator" class="def">dropTrailingPathSeparator</a> :: RawFilePath -> RawFilePath <a href="src/System-Posix-FilePath.html#dropTrailingPathSeparator" class="link">Source</a> <a href="#v:dropTrailingPathSeparator" class="selflink">#</a></p><div class="doc"><p>Remove a trailing path separator</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>dropTrailingPathSeparator "/path/"
|
||
|
</code></strong>"/path"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>dropTrailingPathSeparator "/path////"
|
||
|
</code></strong>"/path"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>dropTrailingPathSeparator "/"
|
||
|
</code></strong>"/"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>dropTrailingPathSeparator "//"
|
||
|
</code></strong>"/"
|
||
|
</pre></div></div><h1 id="g:6">File name manipulations</h1><div class="top"><p class="src"><a id="v:normalise" class="def">normalise</a> :: RawFilePath -> RawFilePath <a href="src/System-Posix-FilePath.html#normalise" class="link">Source</a> <a href="#v:normalise" class="selflink">#</a></p><div class="doc"><p>Normalise a file.</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>normalise "/file/\\test////"
|
||
|
</code></strong>"/file/\\test/"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>normalise "/file/./test"
|
||
|
</code></strong>"/file/test"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>normalise "/test/file/../bob/fred/"
|
||
|
</code></strong>"/test/file/../bob/fred/"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>normalise "../bob/fred/"
|
||
|
</code></strong>"../bob/fred/"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>normalise "./bob/fred/"
|
||
|
</code></strong>"bob/fred/"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>normalise "./bob////.fred/./...///./..///#."
|
||
|
</code></strong>"bob/.fred/.../../#."
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>normalise "."
|
||
|
</code></strong>"."
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>normalise "./"
|
||
|
</code></strong>"./"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>normalise "./."
|
||
|
</code></strong>"./"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>normalise "/./"
|
||
|
</code></strong>"/"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>normalise "/"
|
||
|
</code></strong>"/"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>normalise "bob/fred/."
|
||
|
</code></strong>"bob/fred/"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>normalise "//home"
|
||
|
</code></strong>"/home"
|
||
|
</pre></div></div><div class="top"><p class="src"><a id="v:makeRelative" class="def">makeRelative</a> :: RawFilePath -> RawFilePath -> RawFilePath <a href="src/System-Posix-FilePath.html#makeRelative" class="link">Source</a> <a href="#v:makeRelative" class="selflink">#</a></p><div class="doc"><p>Contract a filename, based on a relative path. Note that the resulting
|
||
|
path will never introduce <code>..</code> paths, as the presence of symlinks
|
||
|
means <code>../b</code> may not reach <code>a/b</code> if it starts from <code>a/c</code>. For a
|
||
|
worked example see
|
||
|
<a href="http://neilmitchell.blogspot.co.uk/2015/10/filepaths-are-subtle-symlinks-are-hard.html">this blog post</a>.</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>makeRelative "/directory" "/directory/file.ext"
|
||
|
</code></strong>"file.ext"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>makeRelative "/Home" "/home/bob"
|
||
|
</code></strong>"/home/bob"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>makeRelative "/home/" "/home/bob/foo/bar"
|
||
|
</code></strong>"bob/foo/bar"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>makeRelative "/fred" "bob"
|
||
|
</code></strong>"bob"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>makeRelative "/file/test" "/file/test/fred"
|
||
|
</code></strong>"fred"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>makeRelative "/file/test" "/file/test/fred/"
|
||
|
</code></strong>"fred/"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>makeRelative "some/path" "some/path/a/b/c"
|
||
|
</code></strong>"a/b/c"
|
||
|
</pre><pre>\p -> makeRelative p p == "."</pre><pre>\p -> makeRelative (takeDirectory p) p `equalFilePath` takeFileName p</pre><p>prop x y -> equalFilePath x y || (isRelative x && makeRelative y x == x) || equalFilePath (y <a href="/">/</a> makeRelative y x) x</p></div></div><div class="top"><p class="src"><a id="v:equalFilePath" class="def">equalFilePath</a> :: RawFilePath -> RawFilePath -> Bool <a href="src/System-Posix-FilePath.html#equalFilePath" class="link">Source</a> <a href="#v:equalFilePath" class="selflink">#</a></p><div class="doc"><p>Equality of two filepaths. The filepaths are normalised
|
||
|
and trailing path separators are dropped.</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>equalFilePath "foo" "foo"
|
||
|
</code></strong>True
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>equalFilePath "foo" "foo/"
|
||
|
</code></strong>True
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>equalFilePath "foo" "./foo"
|
||
|
</code></strong>True
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>equalFilePath "" ""
|
||
|
</code></strong>True
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>equalFilePath "foo" "/foo"
|
||
|
</code></strong>False
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>equalFilePath "foo" "FOO"
|
||
|
</code></strong>False
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>equalFilePath "foo" "../foo"
|
||
|
</code></strong>False
|
||
|
</pre><pre>\p -> equalFilePath p p</pre></div></div><div class="top"><p class="src"><a id="v:isRelative" class="def">isRelative</a> :: RawFilePath -> Bool <a href="src/System-Posix-FilePath.html#isRelative" class="link">Source</a> <a href="#v:isRelative" class="selflink">#</a></p><div class="doc"><p>Check if a path is relative</p><pre>\path -> isRelative path /= isAbsolute path</pre></div></div><div class="top"><p class="src"><a id="v:isAbsolute" class="def">isAbsolute</a> :: RawFilePath -> Bool <a href="src/System-Posix-FilePath.html#isAbsolute" class="link">Source</a> <a href="#v:isAbsolute" class="selflink">#</a></p><div class="doc"><p>Check if a path is absolute</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>isAbsolute "/path"
|
||
|
</code></strong>True
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>isAbsolute "path"
|
||
|
</code></strong>False
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>isAbsolute ""
|
||
|
</code></strong>False
|
||
|
</pre></div></div><div class="top"><p class="src"><a id="v:isValid" class="def">isValid</a> :: RawFilePath -> Bool <a href="src/System-Posix-FilePath.html#isValid" class="link">Source</a> <a href="#v:isValid" class="selflink">#</a></p><div class="doc"><p>Is a FilePath valid, i.e. could you create a file like it?</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>isValid ""
|
||
|
</code></strong>False
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>isValid "\0"
|
||
|
</code></strong>False
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>isValid "/random_ path:*"
|
||
|
</code></strong>True
|
||
|
</pre></div></div><div class="top"><p class="src"><a id="v:makeValid" class="def">makeValid</a> :: RawFilePath -> RawFilePath <a href="src/System-Posix-FilePath.html#makeValid" class="link">Source</a> <a href="#v:makeValid" class="selflink">#</a></p><div class="doc"><p>Take a FilePath and make it valid; does not change already valid FilePaths.</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>makeValid ""
|
||
|
</code></strong>"_"
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>makeValid "file\0name"
|
||
|
</code></strong>"file_name"
|
||
|
</pre><pre>\p -> if isValid p then makeValid p == p else makeValid p /= p</pre><pre>\p -> isValid (makeValid p)</pre></div></div><div class="top"><p class="src"><a id="v:isFileName" class="def">isFileName</a> :: RawFilePath -> Bool <a href="src/System-Posix-FilePath.html#isFileName" class="link">Source</a> <a href="#v:isFileName" class="selflink">#</a></p><div class="doc"><p>Is the given path a valid filename? This includes
|
||
|
"." and "..".</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>isFileName "lal"
|
||
|
</code></strong>True
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>isFileName "."
|
||
|
</code></strong>True
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>isFileName ".."
|
||
|
</code></strong>True
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>isFileName ""
|
||
|
</code></strong>False
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>isFileName "\0"
|
||
|
</code></strong>False
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>isFileName "/random_ path:*"
|
||
|
</code></strong>False
|
||
|
</pre></div></div><div class="top"><p class="src"><a id="v:hasParentDir" class="def">hasParentDir</a> :: RawFilePath -> Bool <a href="src/System-Posix-FilePath.html#hasParentDir" class="link">Source</a> <a href="#v:hasParentDir" class="selflink">#</a></p><div class="doc"><p>Check if the filepath has any parent directories in it.</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>hasParentDir "/.."
|
||
|
</code></strong>True
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>hasParentDir "foo/bar/.."
|
||
|
</code></strong>True
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>hasParentDir "foo/../bar/."
|
||
|
</code></strong>True
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>hasParentDir "foo/bar"
|
||
|
</code></strong>False
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>hasParentDir "foo"
|
||
|
</code></strong>False
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>hasParentDir ""
|
||
|
</code></strong>False
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>hasParentDir ".."
|
||
|
</code></strong>False
|
||
|
</pre></div></div><div class="top"><p class="src"><a id="v:hiddenFile" class="def">hiddenFile</a> :: RawFilePath -> Bool <a href="src/System-Posix-FilePath.html#hiddenFile" class="link">Source</a> <a href="#v:hiddenFile" class="selflink">#</a></p><div class="doc"><p>Whether the file is a hidden file.</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>hiddenFile ".foo"
|
||
|
</code></strong>True
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>hiddenFile "..foo.bar"
|
||
|
</code></strong>True
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>hiddenFile "some/path/.bar"
|
||
|
</code></strong>True
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>hiddenFile "..."
|
||
|
</code></strong>True
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>hiddenFile "dod.bar"
|
||
|
</code></strong>False
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>hiddenFile "."
|
||
|
</code></strong>False
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>hiddenFile ".."
|
||
|
</code></strong>False
|
||
|
<code class="prompt">>>> </code><strong class="userinput"><code>hiddenFile ""
|
||
|
</code></strong>False
|
||
|
</pre></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.17.2</p></div></body></html>
|