-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Expressive file and directory manipulation for Haskell. -- -- A Haskell library for working with files and directories. Includes -- code for pattern matching, finding files, modifying file contents, and -- more. @package FileManipCompat @version 0.18 -- | This module provides functions for traversing a filesystem hierarchy. -- The find function generates a lazy list of matching files, -- while fold performs a left fold. -- -- Both find and fold allow fine control over recursion, -- using the FindClause type. This type is also used to pre-filter -- the results returned by find. -- -- The FindClause type lets you write filtering and recursion -- control expressions clearly and easily. -- -- For example, this clause matches C source files. -- --
-- extension ==? ".c" ||? extension ==? ".h" ---- -- Because FindClause is a monad, you can use the usual monad -- machinery to, for example, lift pure functions into it. -- -- Here's a clause that will return False for any file whose -- directory name contains the word "temp". -- --
-- (isInfixOf "temp") `liftM` directory --module System.FilePath.FindCompat -- | Information collected during the traversal of a directory. data FileInfo FileInfo :: FilePath -> Int -> FileStatus -> FileInfo -- | file path infoPath :: FileInfo -> FilePath -- | current recursion depth infoDepth :: FileInfo -> Int -- | status of file infoStatus :: FileInfo -> FileStatus data FileType BlockDevice :: FileType CharacterDevice :: FileType NamedPipe :: FileType RegularFile :: FileType Directory :: FileType SymbolicLink :: FileType Socket :: FileType Unknown :: FileType -- | Monadic container for file information, allowing for clean -- construction of combinators. Wraps the State monad, but doesn't -- allow get or put. data FindClause a type FilterPredicate = FindClause Bool type RecursionPredicate = FindClause Bool -- | Search a directory recursively, with recursion controlled by a -- RecursionPredicate. Lazily return a sorted list of all files -- matching the given FilterPredicate. Any errors that occur are -- ignored, with warnings printed to stderr. find :: RecursionPredicate -> FilterPredicate -> FilePath -> IO [FilePath] -- | Search a directory recursively, with recursion controlled by a -- RecursionPredicate. Fold over all files found. Any errors that -- occur are ignored, with warnings printed to stderr. The fold -- function is run from "left" to "right", so it should be strict in its -- left argument to avoid space leaks. If you need a right-to-left fold, -- use foldr on the result of findWithHandler instead. fold :: RecursionPredicate -> (a -> FileInfo -> a) -> a -> FilePath -> IO a -- | Search a directory recursively, with recursion controlled by a -- RecursionPredicate. Lazily return a sorted list of all files -- matching the given FilterPredicate. Any errors that occur are -- dealt with by the given handler. findWithHandler :: (FilePath -> SomeException -> IO [FilePath]) -> RecursionPredicate -> FilterPredicate -> FilePath -> IO [FilePath] -- | Search a directory recursively, with recursion controlled by a -- RecursionPredicate. Fold over all files found. Any errors that -- occur are dealt with by the given handler. The fold is strict, and run -- from "left" to "right", so the folded function should be strict in its -- left argument to avoid space leaks. If you need a right-to-left fold, -- use foldr on the result of findWithHandler instead. foldWithHandler :: (FilePath -> a -> SomeException -> IO a) -> RecursionPredicate -> (a -> FileInfo -> a) -> a -> FilePath -> IO a -- | Run the given FindClause on the given FileInfo and -- return its result. This can be useful if you are writing a function to -- pass to fold. -- -- Example: -- --
-- myFoldFunc :: a -> FileInfo -> a -- myFoldFunc a i = let useThisFile = evalClause (fileName ==? "foo") i -- in if useThisFile -- then fiddleWith a -- else a --evalClause :: FindClause a -> FileInfo -> a -- | Return the type of a file. This is much more useful for case analysis -- than the usual functions on FileStatus values. statusType :: FileStatus -> FileType -- | Lift a binary operator into the FindClause monad, so that it -- becomes a combinator. The left hand side of the combinator should be a -- FindClause a, while the right remains a normal value -- of type a. liftOp :: Monad m => (a -> b -> c) -> m a -> b -> m c -- | Return the name of the file being visited. filePath :: FindClause FilePath -- | Return the FileStatus for the current file. fileStatus :: FindClause FileStatus -- | Return the current recursion depth. depth :: FindClause Int -- | Return the current FileInfo. fileInfo :: FindClause FileInfo -- | Unconditionally return True. always :: FindClause Bool -- | Return the file name extension. -- -- Example: -- --
-- extension "foo/bar.txt" => ".txt" --extension :: FindClause FilePath -- | Return the directory name, without the file name. -- -- What this means in practice: -- --
-- directory "foo/bar.txt" => "foo" ---- -- Example in a clause: -- --
-- let hasSuffix = liftOp isSuffixOf -- in directory `hasSuffix` "tests" --directory :: FindClause FilePath -- | Return the file name, without the directory name. -- -- What this means in practice: -- --
-- fileName "foo/bar.txt" => "bar.txt" ---- -- Example: -- --
-- fileName ==? "init.c" --fileName :: FindClause FilePath -- | Return the type of file currently being visited. -- -- Example: -- --
-- fileType ==? RegularFile --fileType :: FindClause FileType -- | Return True if the given path exists, relative to the current -- file. For example, if "foo" is being visited, and you call -- contains "bar", this combinator will return True if -- "foo/bar" exists. contains :: FilePath -> FindClause Bool deviceID :: FindClause DeviceID fileID :: FindClause FileID fileOwner :: FindClause UserID fileGroup :: FindClause GroupID fileSize :: FindClause FileOffset linkCount :: FindClause LinkCount specialDeviceID :: FindClause DeviceID fileMode :: FindClause FileMode accessTime :: FindClause EpochTime modificationTime :: FindClause EpochTime statusChangeTime :: FindClause EpochTime -- | Return the permission bits of the FileMode. filePerms :: FindClause FileMode -- | Return True if any of the given permission bits is set. -- -- Example: -- --
-- anyPerms 0444 --anyPerms :: FileMode -> FindClause Bool -- | If the current file is a symbolic link, return Just the target -- of the link, otherwise Nothing. readLink :: FindClause (Maybe FilePath) -- | If the current file is a symbolic link, return Just the status -- of the ultimate endpoint of the link. Otherwise (including in the case -- of an error), return Nothing. -- -- Example: -- --
-- statusType `liftM` followStatus ==? RegularFile --followStatus :: FindClause (Maybe FileStatus) -- | Return True if the current file's name matches the given -- GlobPattern. (==?) :: Eq a => FindClause a -> a -> FindClause Bool (/=?) :: Eq a => FindClause a -> a -> FindClause Bool (>?) :: Ord a => FindClause a -> a -> FindClause Bool () :: Ord a => FindClause a -> a -> FindClause Bool (>=?) :: Ord a => FindClause a -> a -> FindClause Bool (<=?) :: Ord a => FindClause a -> a -> FindClause Bool -- | This operator is useful to check if bits are set in a FileMode. (.&.?) :: Bits a => FindClause a -> a -> FindClause a (&&?) :: FindClause Bool -> FindClause Bool -> FindClause Bool (||?) :: FindClause Bool -> FindClause Bool -> FindClause Bool instance Eq FileInfo instance Functor FindClause instance Monad FindClause instance Eq FileType instance Ord FileType instance Show FileType instance Eq FileStatus