<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"/><title>System.Posix.FilePath</title><linkhref="ocean.css"rel="stylesheet"type="text/css"title="Ocean"/><scriptsrc="haddock-util.js"type="text/javascript"></script><scripttype="text/javascript">//<![CDATA[
</pre></div></div><divclass="top"><pclass="src"><aname="v:getSearchPath"class="def">getSearchPath</a> :: <ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/System-IO.html#t:IO">IO</a> [<ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a>] <ahref="src/System-Posix-FilePath.html#getSearchPath"class="link">Source</a></p><divclass="doc"><p>Get a list of <code><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a></code>s in the $PATH variable.</p></div></div><h1id="g:3">Extension functions</h1><divclass="top"><pclass="src"><aname="v:splitExtension"class="def">splitExtension</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -> (<ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a>, <ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a>) <ahref="src/System-Posix-FilePath.html#splitExtension"class="link">Source</a></p><divclass="doc"><p>Split a <code><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a></code> into a path+filename and extension</p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>splitExtension "file.exe"
</pre><pre>\path -> uncurry (BS.append) (splitExtension path) == path</pre></div></div><divclass="top"><pclass="src"><aname="v:takeExtension"class="def">takeExtension</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a><ahref="src/System-Posix-FilePath.html#takeExtension"class="link">Source</a></p><divclass="doc"><p>Get the final extension from a <code><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a></code></p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>takeExtension "file.exe"
</pre></div></div><divclass="top"><pclass="src"><aname="v:replaceExtension"class="def">replaceExtension</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a><ahref="src/System-Posix-FilePath.html#replaceExtension"class="link">Source</a></p><divclass="doc"><p>Change a file's extension</p><pre>\path -> let ext = takeExtension path in replaceExtension path ext == path</pre></div></div><divclass="top"><pclass="src"><aname="v:dropExtension"class="def">dropExtension</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a><ahref="src/System-Posix-FilePath.html#dropExtension"class="link">Source</a></p><divclass="doc"><p>Drop the final extension from a <code><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a></code></p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>dropExtension "file.exe"
</pre></div></div><divclass="top"><pclass="src"><aname="v:addExtension"class="def">addExtension</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a><ahref="src/System-Posix-FilePath.html#addExtension"class="link">Source</a></p><divclass="doc"><p>Add an extension to a <code><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a></code></p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>addExtension "file"".exe"
</pre></div></div><divclass="top"><pclass="src"><aname="v:hasExtension"class="def">hasExtension</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Bool.html#t:Bool">Bool</a><ahref="src/System-Posix-FilePath.html#hasExtension"class="link">Source</a></p><divclass="doc"><p>Check if a <code><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a></code> has an extension</p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>hasExtension "file"
</pre></div></div><divclass="top"><pclass="src"><aname="v:-60-.-62-"class="def">(<.>)</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a><ahref="src/System-Posix-FilePath.html#%3C.%3E"class="link">Source</a></p><divclass="doc"><p>Operator version of <code><ahref="System-Posix-FilePath.html#v:addExtension">addExtension</a></code></p></div></div><divclass="top"><pclass="src"><aname="v:splitExtensions"class="def">splitExtensions</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -> (<ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a>, <ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a>) <ahref="src/System-Posix-FilePath.html#splitExtensions"class="link">Source</a></p><divclass="doc"><p>Split a <code><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a></code> on the first extension.</p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>splitExtensions "/path/file.tar.gz"
</pre></div></div><divclass="top"><pclass="src"><aname="v:takeExtensions"class="def">takeExtensions</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a><ahref="src/System-Posix-FilePath.html#takeExtensions"class="link">Source</a></p><divclass="doc"><p>Take all extensions from a <code><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a></code></p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>takeExtensions "/path/file.tar.gz"
</pre></div></div><divclass="top"><pclass="src"><aname="v:stripExtension"class="def">stripExtension</a> :: <ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Maybe.html#t:Maybe">Maybe</a><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a><ahref="src/System-Posix-FilePath.html#stripExtension"class="link">Source</a></p><divclass="doc"><p>Drop the given extension from a FilePath, and the <code>"."</code> preceding it.
Returns <code><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Maybe.html#v:Nothing">Nothing</a></code> if the FilePath does not have the given extension, or
<code><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Maybe.html#v:Just">Just</a></code> and the part before the extension if it does.</p><p>This function can be more predictable than <code><ahref="System-Posix-FilePath.html#v:dropExtensions">dropExtensions</a></code>,
especially if the filename might itself contain <code>.</code> characters.</p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>stripExtension "hs.o""foo.x.hs.o"
</pre></div></div><divclass="top"><pclass="src"><aname="v:takeBaseName"class="def">takeBaseName</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a><ahref="src/System-Posix-FilePath.html#takeBaseName"class="link">Source</a></p><divclass="doc"><p>Get the file name, without a trailing extension</p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>takeBaseName "path/file.tar.gz"
</pre></div></div><divclass="top"><pclass="src"><aname="v:replaceBaseName"class="def">replaceBaseName</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a><ahref="src/System-Posix-FilePath.html#replaceBaseName"class="link">Source</a></p><divclass="doc"><p>Change the base name</p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>replaceBaseName "path/file.tar.gz""bob"
</pre><pre>\path -> replaceBaseName path (takeBaseName path) == path</pre></div></div><divclass="top"><pclass="src"><aname="v:takeDirectory"class="def">takeDirectory</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a><ahref="src/System-Posix-FilePath.html#takeDirectory"class="link">Source</a></p><divclass="doc"><p>Get the directory, moving up one level if it's already a directory</p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>takeDirectory "path/file.txt"
</pre></div></div><divclass="top"><pclass="src"><aname="v:-60--47--62-"class="def">(</>)</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a><ahref="src/System-Posix-FilePath.html#%3C%2F%3E"class="link">Source</a></p><divclass="doc"><p>Operator version of combine</p></div></div><divclass="top"><pclass="src"><aname="v:splitPath"class="def">splitPath</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -> [<ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a>] <ahref="src/System-Posix-FilePath.html#splitPath"class="link">Source</a></p><divclass="doc"><p>Split a path into a list of components:</p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>splitPath "/path/to/file.txt"
</pre></div></div><h1id="g:5">Trailing slash functions</h1><divclass="top"><pclass="src"><aname="v:hasTrailingPathSeparator"class="def">hasTrailingPathSeparator</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Bool.html#t:Bool">Bool</a><ahref="src/System-Posix-FilePath.html#hasTrailingPathSeparator"class="link">Source</a></p><divclass="doc"><p>Check if the last character of a <code><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a></code> is <code><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Prelude.html#v:-47-">/</a></code>.</p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>hasTrailingPathSeparator "/path/"
</pre></div></div><h1id="g:6">File name manipulations</h1><divclass="top"><pclass="src"><aname="v:normalise"class="def">normalise</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a><ahref="src/System-Posix-FilePath.html#normalise"class="link">Source</a></p><divclass="doc"><p>Normalise a file.</p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>normalise "/file/\\test////"
</pre></div></div><divclass="top"><pclass="src"><aname="v:makeRelative"class="def">makeRelative</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a><ahref="src/System-Posix-FilePath.html#makeRelative"class="link">Source</a></p><divclass="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
<ahref="http://neilmitchell.blogspot.co.uk/2015/10/filepaths-are-subtle-symlinks-are-hard.html">this blog post</a>.</p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>makeRelative "/directory""/directory/file.ext"
</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 <ahref="/">/</a> makeRelative y x) x</p></div></div><divclass="top"><pclass="src"><aname="v:equalFilePath"class="def">equalFilePath</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Bool.html#t:Bool">Bool</a><ahref="src/System-Posix-FilePath.html#equalFilePath"class="link">Source</a></p><divclass="doc"><p>Equality of two filepaths. The filepaths are normalised
and trailing path separators are dropped.</p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>equalFilePath "foo""foo"
</pre><pre>\p -> equalFilePath p p</pre></div></div><divclass="top"><pclass="src"><aname="v:isRelative"class="def">isRelative</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Bool.html#t:Bool">Bool</a><ahref="src/System-Posix-FilePath.html#isRelative"class="link">Source</a></p><divclass="doc"><p>Check if a path is relative</p><pre>\path -> isRelative path /= isAbsolute path</pre></div></div><divclass="top"><pclass="src"><aname="v:isAbsolute"class="def">isAbsolute</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Bool.html#t:Bool">Bool</a><ahref="src/System-Posix-FilePath.html#isAbsolute"class="link">Source</a></p><divclass="doc"><p>Check if a path is absolute</p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>isAbsolute "/path"
</pre></div></div><divclass="top"><pclass="src"><aname="v:isValid"class="def">isValid</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Bool.html#t:Bool">Bool</a><ahref="src/System-Posix-FilePath.html#isValid"class="link">Source</a></p><divclass="doc"><p>Is a FilePath valid, i.e. could you create a file like it?</p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>isValid ""
</pre></div></div><divclass="top"><pclass="src"><aname="v:makeValid"class="def">makeValid</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a><ahref="src/System-Posix-FilePath.html#makeValid"class="link">Source</a></p><divclass="doc"><p>Take a FilePath and make it valid; does not change already valid FilePaths.</p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>makeValid ""
</pre><pre>\p -> if isValid p then makeValid p == p else makeValid p /= p</pre><pre>\p -> isValid (makeValid p)</pre></div></div><divclass="top"><pclass="src"><aname="v:isFileName"class="def">isFileName</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Bool.html#t:Bool">Bool</a><ahref="src/System-Posix-FilePath.html#isFileName"class="link">Source</a></p><divclass="doc"><p>Is the given path a valid filename? This includes
"." and "..".</p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>isFileName "lal"
</pre></div></div><divclass="top"><pclass="src"><aname="v:hasParentDir"class="def">hasParentDir</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Bool.html#t:Bool">Bool</a><ahref="src/System-Posix-FilePath.html#hasParentDir"class="link">Source</a></p><divclass="doc"><p>Check if the filepath has any parent directories in it.</p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>hasParentDir "/.."
</pre></div></div><divclass="top"><pclass="src"><aname="v:hiddenFile"class="def">hiddenFile</a> :: <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html#t:RawFilePath">RawFilePath</a> -><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Bool.html#t:Bool">Bool</a><ahref="src/System-Posix-FilePath.html#hiddenFile"class="link">Source</a></p><divclass="doc"><p>Whether the file is a hidden file.</p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>hiddenFile ".foo"
</pre></div></div><divclass="top"><pclass="src">module <ahref="https://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-ByteString-FilePath.html">System.Posix.ByteString.FilePath</a></p></div></div></div><divid="footer"><p>Produced by <ahref="http://www.haskell.org/haddock/">Haddock</a> version 2.14.3</p></div></body></html>