[Haskell] howto implement the getDirectoryContents by hand

Sun Yi Ming yimings at cgogo.com
Wed Apr 27 05:36:55 EDT 2005

hi all,
   i even know there is a getDirectoryContents function in lib,but
   that's implemented by primitive function getDirContents,so i try to
   implement it use openDirStream,readDirStream but failed to
   recursive the contents, below is my try code:

module Test1 where

import System.Directory
import System.Posix.Directory
import Control.Monad

dirName = "/home/wise/source/haskell"

ls :: FilePath -> IO [FilePath]
ls dname = do dirs <- openDirStream dname
              path <- readDirStream dirs
              return [path] -- so how to recursive this

test = print =<< ls dirName

any help is appreciated.

Sun Yi Ming   

More information about the Haskell mailing list