Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Provides path traversal functions much like Python's os.walk.
- type Callback a = FilePath -> [FilePath] -> [FilePath] -> IO a
- pathWalk :: FilePath -> Callback () -> IO ()
- data WalkStatus
- pathWalkInterruptible :: FilePath -> Callback WalkStatus -> IO ()
Documentation
type Callback a = FilePath -> [FilePath] -> [FilePath] -> IO 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 :: FilePath -> Callback () -> IO () 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.
Continue | Continue recursing all subdirectories. |
StopRecursing | Do not traverse deeper. |
Stop | Stop recursing entirely. |
pathWalkInterruptible :: FilePath -> Callback WalkStatus -> IO () Source
Traverses a directory tree, just like pathWalk
, except that
the callback can determine whether to continue traversal. See
WalkStatus
.