bos / filemanip

A Haskell library for working with files and directories. Includes code for pattern matching, finding files, modifying file contents, and more.
http://bitbucket.org/bos/filemanip
Other
27 stars 9 forks source link

System.FilePath.Find: a simple entrypoint which returns FileInfo #19

Open andreasabel opened 7 years ago

andreasabel commented 7 years ago

Hi, I was missing a simple entry point like find but which also returns the FileInfo.

-- | Search a directory recursively, with recursion controlled by a
--   'RecursionPredicate'.  Lazily return a unsorted list of all files
--   matching the given 'FilterPredicate'.  Any errors that occur are
--   ignored, with warnings printed to 'stderr'.
findWithInfo
  :: RecursionPredicate  -- ^ Control recursion into subdirectories.
  -> FilterPredicate     -- ^ Decide whether a file appears in the result.
  -> FilePath            -- ^ Directory to start searching.
  -> IO [FileInfo]       -- ^ Files that matched the 'FilterPredicate'.
findWithInfo recurse filt dir = fold recurse act [] dir
  where
  -- Add file to list front when it matches the filter
  act :: [FileInfo] -> FileInfo -> [FileInfo]
  act fs f
    | evalClause filt f = f:fs
    | otherwise = fs

This one could be useful, as it allows e.g. sorting the result by other criteria than the file name. The result of find can be obtained from this one by projecting the infoPath.