[Haskell-beginners] Folders and sub-folders

Mike Houghton mike_k_houghton at yahoo.co.uk
Thu Feb 25 18:41:20 UTC 2016


Hi,

I’m trying to build up a list of all folders (including subfolders) from a given root folder.

So I have

folders :: FilePath -> IO [FilePath]
folders fp  = do 
    all <- getDirectoryContents fp
   filterM doesDirectoryExist $ map (fp </>) all
  
and this just gets the immediate folders within the given folder. 

I’m stuck on how to recursively call folders and build up the IO [FilePath]


folders :: FilePath -> IO [FilePath]
folders fp  = do
    all <- getDirectoryContents fp
    -- z :: IO  [FilePath]
    let z = filterM doesDirectoryExist $ map (fp </>) all
    — z’ :: [FilePath]
    z' <- z
    — ?? what should happen here?
    z : (map folders z’)    

   
   Couldn't match expected type ‘[FilePath]’
                with actual type ‘IO [FilePath]’
    In the first argument of ‘(:)’, namely ‘z’
    In a stmt of a 'do' block: z : (map folders z')
etc... 
  

Thanks

Mike


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160225/5d9c88d2/attachment.html>


More information about the Beginners mailing list