Tom Hofte wrote:
I'm looking for a way to iteratively read all the files in a directory and its subdirectories, given the filepath of the top-level dir. For example, I want to find a file, corresponding to a given filename, in a directory and its subdirectories.
Is there a way to implement this in Haskell?
BTW, one other caveat (which applies to all of the examples so far): doesDirectoryExist doesn't distinguish between directories and symlinks to directories. Consequently, any directory-traversal algorithm which uses doesDirectoryExist to identify directories will behave incorrectly in the presence of symlinks. In the worst case, you can get into an infinite loop. The only alternative is to use the functions from the Posix library (getSymbolicLinkStatus and isDirectory) instead, e.g.:
import Posix
doesDirectoryReallyExist :: FilePath -> IO Bool doesDirectoryReallyExist path = do stat <- getSymbolicLinkStatus return $ isDirectory stat
-- Glynn Clements <glynn.clements@virgin.net>