name: directory-tree
version: 0.2.1
homepage: http://coder.bsimmons.name/blog/2009/05/directory-tree-module-released/
synopsis: A simple directory-like tree datatype, with useful IO functions
description: A simple directory-like tree datatype, with useful IO functions and Foldable and Traversable instance
.
Provides a simple data structure mirroring a directory tree on the
filesystem, as well as useful functions for reading and writing
file and directory structures in the IO monad.
.
Importing the library and optional (useful) Foldable and Traverable libraries:
.
> import System.Directory.Tree
> import qualified Data.Foldable as F
> import qualified Data.Traversable as T
.
Write a hand-made directory tree of textfiles (strings) to the disk.
Simulates creating a new user Tux's home directory on a unix machine:
.
> writeDirectory$ "/home" :/ Dir "Tux" [File "README" "Welcome!"]
.
"read" a directory by opening all the files at a filepath with readFile,
returning an 'AnchoredDirTree String' (d2). Then check for any IO failures:
.
> do (base :/ d2) <- readDirectory "../parent_dir/dir2/"
> let failed = anyFailed d2
> if failed then ...
.
Use Foldable instance function to concat a directory 'dir' of text files into a
single file under the same directory:
.
> do (b :/ dt) <- readDirectory dir
> let f = F.concat dt
> return$ b :/ File "ALL_TEXT" f
.
Open all the files in the current directory as lazy bytestrings, ignoring
the base path in Anchored wrapper:
.
> import qualified Data.ByteString.Lazy as B
> do (_ :/ dTree) <- readDirectoryWith B.readFile "./"
.
*NOTE:* the IO functions like `readDirectoryWith` in this library use standard lazy IO
IOfunctions and will (necessarily) traverse an entire system directory tree before
returning a DirTree constructor. This unfortunately makes it not suitable for large
directory trees.
Any ideas or suggestions for improvements would be most welcomed :-)
.
category: Data, System
license: BSD3
license-file: LICENSE
copyright: (c) 2010, Brandon Simmons <brandon.m.simmons@gmail.com>
author: Brandon Simmons
maintainer: Brandon Simmons <brandon.m.simmons@gmail.com>
cabal-version: >= 1.2.0
build-type: Simple
tested-with: GHC <=6.12.1
extra-source-files: examples.hs
library
exposed-modules: System.Directory.Tree
build-depends: base <5, filepath <2, directory <2
ghc-options: -Wall