[Haskell] Reading a directory tree

David Brown haskell at davidb.org
Tue Jun 29 11:21:00 EDT 2004


On Mon, Jun 28, 2004 at 11:08:38AM -0400, Isaac Jones wrote:

> My basic requirement is that they should be functions useful for
> system administration.
> 
> We've sucked in some functions in from GHC and from Cabal[1]. It would
> be nice if we could just have a dumping ground for related functions
> that people have written.

Functions that recursively iterate directories should _never_ follow
symlinks as if they were directories (possibly optionally).  It is
rarely what is wanted.

To fix this, use getSymbolicLinkStatus instead of getFileStatus.

For directory iteration, the called function will usually need to know
at least some information about each file.  Since you have to get a
FileStatus for each file anyway, you might as well pass it to each
child.

Also, it is important to handle errors that happen during iteration.  If
you try statting, or reading something incorrect, you can cause
exceptions, which will need to be handled.

SlurpDirectory has some useful code (in darcs), but is fairly specific
to darcs.  It is actually fairly challenging to come up with useful
directory iteration that is generic.  What about filtering?

Dave Brown


More information about the Haskell mailing list