+moviePaths dir = do
+ paths <- filePaths (\filename ->
+ any (`isSuffixOf` filename) movieExtenstions) dir
+ -- Keep only the relative path.
+ return $ map (drop $ Data.List.length dir + 1) paths
+
+filePaths :: (String -> Bool) -> FilePath -> IO [FilePath]
+filePaths predicat baseDir = do
+ processDir baseDir
+ where
+ processDir dir = do
+ contents <- getDirectoryContents dir
+ foldM (\acc entry -> do
+ let absDir = dir </> entry
+ doesDirectoryExist absDir >>= \exists ->
+ if exists
+ then do
+ paths <- processDir absDir
+ return (paths ++ acc)
+ else
+ if predicat entry
+ then
+ return (absDir : acc)
+ else
+ return acc)
+ []
+ (contents \\ ["..", "."])
+