@@ -7,6 +7,7 @@ module Hakyll.Core.Util.File
77 , isFileInternal
88 ) where
99
10+import Control.Applicative ((<$>))
1011import System.Time (ClockTime)
1112import Control.Monad (forM, filterM)
1213import Data.List (isPrefixOf)
@@ -27,22 +28,24 @@ makeDirectories :: FilePath -> IO ()
2728makeDirectories = createDirectoryIfMissing True . takeDirectory
2829
2930-- | Get all contents of a directory. Note that files starting with a dot (.)
30−-- will be ignored.
31+-- will be ignored.
3132--
32−getRecursiveContents :: FilePath -> IO [FilePath]
33−getRecursiveContents topdir = do
33+getRecursiveContents :: Bool -- ^ Include directories?
34+ -> FilePath -- ^ Directory to search
35+ -> IO [FilePath] -- ^ List of files found
36+getRecursiveContents includeDirs topdir = do
3437 topdirExists <- doesDirectoryExist topdir
35− if topdirExists
36− then do names <- getDirectoryContents topdir
37− let properNames = filter isProper names
38− paths <- forM properNames $ \name -> do
39− let path = topdir </> name
40− isDirectory <- doesDirectoryExist path
41− if isDirectory
42− then getRecursiveContents path
43− else return [normalise path]
44− return (concat paths)
45− else return []
38+ if not topdirExists
39+ then return []
40+ else do
41+ names <- filter isProper <$> getDirectoryContents topdir
42+ paths <- forM names $ \name -> do
43+ let path = normalise $ topdir </> name
44+ isDirectory <- doesDirectoryExist path
45+ if isDirectory then getRecursiveContents includeDirs path
46+ else return [path]
47+ return $ if includeDirs then topdir : concat paths
48+ else concat paths
4649 where
4750 isProper = not . (== ".") . take 1
4851