pathwalk-0.3.1.2: Path walking utilities for Haskell programs

Safe HaskellNone
LanguageHaskell2010

System.Directory.PathWalk

Description

Provides path traversal functions much like Python's os.walk.

Synopsis

Documentation

type Callback m a = FilePath -> [FilePath] -> [FilePath] -> m a Source

Called with a directory, list of relative subdirectories, and a list of file names. If using pathWalk, the callback always returns '()'. If using pathWalkInterruptible, it returns whether to continue, prevent recursing further, or stop traversal entirely.

pathWalk :: MonadIO m => FilePath -> Callback m () -> m () Source

pathWalk recursively enumerates the given root directory, calling callback once per directory with the traversed directory name, a list of subdirectories, and a list of files.

The subdirectories and file names are always relative to the root given.

pathWalk "src" $ \dir subdirs files -> do
  forM_ files $ \file -> do
    when ("Test.hs" `isSuffixOf` file) $ do
      registerTestFile $ dir </> file

data WalkStatus Source

The callback given to pathWalkInterruptible returns a WalkStatus which determines which subsequent directories are traversed.

Constructors

Continue

Continue recursing all subdirectories.

StopRecursing

Do not traverse deeper.

Stop

Stop recursing entirely.

pathWalkInterruptible :: MonadIO m => FilePath -> Callback m WalkStatus -> m () Source

Traverses a directory tree, just like pathWalk, except that the callback can determine whether to continue traversal. See WalkStatus.

pathWalkAccumulate :: (MonadIO m, Monoid o) => FilePath -> Callback m o -> m o Source

Traverses a directory tree, just like pathWalk. The difference is that each callback returns a Monoid value, all of which are accumulated into the result. Note that this uses WriterT and thus frequently appends to the right of the monoid. Be careful to avoid accidental quadratic behavior by using a data structure that supports fast appends. For example, use Data.Sequence instead of a list.

pathWalkLazy :: MonadIO m => FilePath -> m [(FilePath, [FilePath], [FilePath])] Source

The lazy version of pathWalk. Instead of running a callback per directory, it returns a lazy list that reads from the filesystem as the list is evaluated.

pathWalkLazy does not allow selective recursion. For richer functionality, see the directory-tree package at https://hackage.haskell.org/package/directory-tree