1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
{-# LANGUAGE CPP #-}
#if __GLASGOW_HASKELL__ >= 704
{-# LANGUAGE Safe #-}
#endif
{- |
Module : System.FilePath
Copyright : (c) Neil Mitchell 2005-2014
License : BSD3
Maintainer : ndmitchell@gmail.com
Stability : stable
Portability : portable
A library for 'FilePath' manipulations, using Posix or Windows filepaths
depending on the platform.
Both "System.FilePath.Posix" and "System.FilePath.Windows" provide the
same interface.
Given the example 'FilePath': @\/directory\/file.ext@
We can use the following functions to extract pieces.
* 'takeFileName' gives @\"file.ext\"@
* 'takeDirectory' gives @\"\/directory\"@
* 'takeExtension' gives @\".ext\"@
* 'dropExtension' gives @\"\/directory\/file\"@
* 'takeBaseName' gives @\"file\"@
And we could have built an equivalent path with the following expressions:
* @\"\/directory\" '</>' \"file.ext\"@.
* @\"\/directory\/file" '<.>' \"ext\"@.
* @\"\/directory\/file.txt" '-<.>' \"ext\"@.
Each function in this module is documented with several examples,
which are also used as tests.
Here are a few examples of using the @filepath@ functions together:
/Example 1:/ Find the possible locations of a Haskell module @Test@ imported from module @Main@:
@['replaceFileName' path_to_main \"Test\" '<.>' ext | ext <- [\"hs\",\"lhs\"] ]@
/Example 2:/ Download a file from @url@ and save it to disk:
@do let file = 'makeValid' url
System.Directory.createDirectoryIfMissing True ('takeDirectory' file)@
/Example 3:/ Compile a Haskell file, putting the @.hi@ file under @interface@:
@'takeDirectory' file '</>' \"interface\" '</>' ('takeFileName' file '-<.>' \"hi\")@
References:
[1] <http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247.aspx Naming Files, Paths and Namespaces> (Microsoft MSDN)
-}
#if defined(mingw32_HOST_OS) || defined(__MINGW32__)
module System.FilePath(
-- * Separator predicates
FilePath,
pathSeparator, pathSeparators, isPathSeparator,
searchPathSeparator, isSearchPathSeparator,
extSeparator, isExtSeparator,
-- * @$PATH@ methods
splitSearchPath, getSearchPath,
-- * Extension functions
splitExtension,
takeExtension, replaceExtension, (-<.>), dropExtension, addExtension, hasExtension, (<.>),
splitExtensions, dropExtensions, takeExtensions, replaceExtensions, isExtensionOf,
stripExtension,
-- * Filename\/directory functions
splitFileName,
takeFileName, replaceFileName, dropFileName,
takeBaseName, replaceBaseName,
takeDirectory, replaceDirectory,
combine, (</>),
splitPath, joinPath, splitDirectories,
-- * Drive functions
splitDrive, joinDrive,
takeDrive, hasDrive, dropDrive, isDrive,
-- * Trailing slash functions
hasTrailingPathSeparator,
addTrailingPathSeparator,
dropTrailingPathSeparator,
-- * File name manipulations
normalise, equalFilePath,
makeRelative,
isRelative, isAbsolute,
isValid, makeValid
) where
import System.FilePath.Windows
#else
module System.FilePath(
-- * Separator predicates
FilePath,
pathSeparator, pathSeparators, isPathSeparator,
searchPathSeparator, isSearchPathSeparator,
extSeparator, isExtSeparator,
-- * @$PATH@ methods
splitSearchPath, getSearchPath,
-- * Extension functions
splitExtension,
takeExtension, replaceExtension, (-<.>), dropExtension, addExtension, hasExtension, (<.>),
splitExtensions, dropExtensions, takeExtensions, replaceExtensions, isExtensionOf,
stripExtension,
-- * Filename\/directory functions
splitFileName,
takeFileName, replaceFileName, dropFileName,
takeBaseName, replaceBaseName,
takeDirectory, replaceDirectory,
combine, (</>),
splitPath, joinPath, splitDirectories,
-- * Drive functions
splitDrive, joinDrive,
takeDrive, hasDrive, dropDrive, isDrive,
-- * Trailing slash functions
hasTrailingPathSeparator,
addTrailingPathSeparator,
dropTrailingPathSeparator,
-- * File name manipulations
normalise, equalFilePath,
makeRelative,
isRelative, isAbsolute,
isValid, makeValid
) where
import System.FilePath.Posix
#endif
|