shake-0.19.1: Build system library, like Make, but more accurate dependencies.

Safe Haskell | Safe
Language | Haskell2010

Development.Shake.FilePath

Description

A module for `FilePath` operations exposing System.FilePath plus some additional operations.

Windows note: The extension methods (`<.>`, `takeExtension` etc) use the Posix variants since on Windows `"//*" `<.>` "txt"` produces `"//*\\.txt"` (which is bad for `FilePattern` values).

Synopsis

- type FilePath = String
- dropTrailingPathSeparator :: FilePath -> FilePath
- normalise :: FilePath -> FilePath
- combine :: FilePath -> FilePath -> FilePath
- isPathSeparator :: Char -> Bool
- splitSearchPath :: String -> [FilePath]
- addTrailingPathSeparator :: FilePath -> FilePath
- makeRelative :: FilePath -> FilePath -> FilePath
- (-<.>) :: FilePath -> String -> FilePath
- (</>) :: FilePath -> FilePath -> FilePath
- dropDrive :: FilePath -> FilePath
- dropFileName :: FilePath -> FilePath
- equalFilePath :: FilePath -> FilePath -> Bool
- extSeparator :: Char
- getSearchPath :: IO [FilePath]
- hasDrive :: FilePath -> Bool
- hasTrailingPathSeparator :: FilePath -> Bool
- isAbsolute :: FilePath -> Bool
- isDrive :: FilePath -> Bool
- isExtSeparator :: Char -> Bool
- isExtensionOf :: String -> FilePath -> Bool
- isRelative :: FilePath -> Bool
- isSearchPathSeparator :: Char -> Bool
- isValid :: FilePath -> Bool
- joinDrive :: FilePath -> FilePath -> FilePath
- joinPath :: [FilePath] -> FilePath
- makeValid :: FilePath -> FilePath
- pathSeparator :: Char
- pathSeparators :: [Char]
- replaceBaseName :: FilePath -> String -> FilePath
- replaceDirectory :: FilePath -> String -> FilePath
- replaceExtensions :: FilePath -> String -> FilePath
- replaceFileName :: FilePath -> String -> FilePath
- searchPathSeparator :: Char
- splitDirectories :: FilePath -> [FilePath]
- splitDrive :: FilePath -> (FilePath, FilePath)
- splitFileName :: FilePath -> (String, String)
- splitPath :: FilePath -> [FilePath]
- stripExtension :: String -> FilePath -> Maybe FilePath
- takeBaseName :: FilePath -> String
- takeDirectory :: FilePath -> FilePath
- takeDrive :: FilePath -> FilePath
- takeFileName :: FilePath -> FilePath
- addExtension :: FilePath -> String -> FilePath
- (<.>) :: FilePath -> String -> FilePath
- dropExtension :: FilePath -> FilePath
- dropExtensions :: FilePath -> FilePath
- hasExtension :: FilePath -> Bool
- replaceExtension :: FilePath -> String -> FilePath
- splitExtension :: FilePath -> (String, String)
- splitExtensions :: FilePath -> (FilePath, String)
- takeExtension :: FilePath -> String
- takeExtensions :: FilePath -> String
- dropDirectory1 :: FilePath -> FilePath
- takeDirectory1 :: FilePath -> FilePath
- replaceDirectory1 :: FilePath -> String -> FilePath
- makeRelativeEx :: FilePath -> FilePath -> IO (Maybe FilePath)
- normaliseEx :: FilePath -> FilePath
- toNative :: FilePath -> FilePath
- toStandard :: FilePath -> FilePath
- exe :: String

# Documentation

type FilePath = String #

dropTrailingPathSeparator :: FilePath -> FilePath #

normalise :: FilePath -> FilePath #

combine :: FilePath -> FilePath -> FilePath #

isPathSeparator :: Char -> Bool #

splitSearchPath :: String -> [FilePath] #

addTrailingPathSeparator :: FilePath -> FilePath #

makeRelative :: FilePath -> FilePath -> FilePath #

(-<.>) :: FilePath -> String -> FilePath #

(</>) :: FilePath -> FilePath -> FilePath #

dropDrive :: FilePath -> FilePath #

dropFileName :: FilePath -> FilePath #

equalFilePath :: FilePath -> FilePath -> Bool #

extSeparator :: Char #

getSearchPath :: IO [FilePath] #

hasDrive :: FilePath -> Bool #

hasTrailingPathSeparator :: FilePath -> Bool #

isAbsolute :: FilePath -> Bool #

isDrive :: FilePath -> Bool #

isExtSeparator :: Char -> Bool #

isExtensionOf :: String -> FilePath -> Bool #

isRelative :: FilePath -> Bool #

isSearchPathSeparator :: Char -> Bool #

isValid :: FilePath -> Bool #

joinDrive :: FilePath -> FilePath -> FilePath #

joinPath :: [FilePath] -> FilePath #

makeValid :: FilePath -> FilePath #

pathSeparator :: Char #

pathSeparators :: [Char] #

replaceBaseName :: FilePath -> String -> FilePath #

replaceDirectory :: FilePath -> String -> FilePath #

replaceExtensions :: FilePath -> String -> FilePath #

replaceFileName :: FilePath -> String -> FilePath #

searchPathSeparator :: Char #

splitDirectories :: FilePath -> [FilePath] #

splitDrive :: FilePath -> (FilePath, FilePath) #

splitFileName :: FilePath -> (String, String) #

splitPath :: FilePath -> [FilePath] #

stripExtension :: String -> FilePath -> Maybe FilePath #

takeBaseName :: FilePath -> String #

takeDirectory :: FilePath -> FilePath #

takeDrive :: FilePath -> FilePath #

takeFileName :: FilePath -> FilePath #

addExtension :: FilePath -> String -> FilePath #

(<.>) :: FilePath -> String -> FilePath #

dropExtension :: FilePath -> FilePath #

dropExtensions :: FilePath -> FilePath #

hasExtension :: FilePath -> Bool #

replaceExtension :: FilePath -> String -> FilePath #

splitExtension :: FilePath -> (String, String) #

splitExtensions :: FilePath -> (FilePath, String) #

takeExtension :: FilePath -> String #

takeExtensions :: FilePath -> String #

dropDirectory1 :: FilePath -> FilePath Source #

Drop the first directory from a `FilePath`. Should only be used on relative paths.

    dropDirectory1 "aaa/bbb" == "bbb"
    dropDirectory1 "aaa/" == ""
    dropDirectory1 "aaa" == ""
    dropDirectory1 "" == ""

takeDirectory1 :: FilePath -> FilePath Source #

Take the first component of a `FilePath`. Should only be used on relative paths.

    takeDirectory1 "aaa/bbb" == "aaa"
    takeDirectory1 "aaa/" == "aaa"
    takeDirectory1 "aaa" == "aaa"

replaceDirectory1 :: FilePath -> String -> FilePath Source #

Replace the first component of a `FilePath`. Should only be used on relative paths.

    replaceDirectory1 "root/file.ext" "directory" == "directory/file.ext"
    replaceDirectory1 "root/foo/bar/file.ext" "directory" == "directory/foo/bar/file.ext"

makeRelativeEx :: FilePath -> FilePath -> IO (Maybe FilePath) Source #

Make a path relative. Returns Nothing only when the given paths are on different drives. This will try the pure function makeRelative first. If that fails, the paths are canonicalised (removing any indirection and symlinks) and a relative path is derived from there.

    > -- Given that "/root/a/" is not a symlink
    > makeRelativeEx "/root/a/" "/root/b/file.out"
    Just "../b/file.out"

    > -- Given that "/root/c/" is a symlink to "/root/e/f/g/"
    > makeRelativeEx "/root/c/" "/root/b/file.out"
    Just "../../../b/file.out"

    > -- On Windows
    > makeRelativeEx "C:\\foo" "D:\\foo\\bar"
    Nothing

normaliseEx :: FilePath -> FilePath Source #

Normalise a `FilePath`, applying the rules:

- All `pathSeparators` become `pathSeparator` (`/` on Linux, `\` on Windows)
- `foo/bar/../baz` becomes `foo/baz` (not universally true in the presence of symlinks)
- `foo/./bar` becomes `foo/bar`
- `foo//bar` becomes `foo/bar`

This function is not based on the `normalise` function from the `filepath` library, as that function is quite broken.

toNative :: FilePath -> FilePath Source #

Convert to native path separators, namely `\` on Windows.

toStandard :: FilePath -> FilePath Source #

Convert all path separators to `/`, even on Windows.

exe :: String Source #

The extension of executables, `"exe"` on Windows and `""` otherwise.