I just released version 0.1 of FileManip, a Haskell library I put together to make it easier to futz about with files in the filesystem.
There are a few different components to the package.
module lets you search the filesystem for files, after the manner of
find program. It provides a nice embedded language for
building filters and controlling recursion, so you can write
readable expressions like this:
find always (fileType ==? RegularFile &&? extension ==? ".hs") "myPath"
This will return a list of all Haskell source files under
The list is built lazily, so if you have a million files in your tree,
but you only examine the first ten elements of the list, no extra work
The obvious counterparts to the
Find module in other languages would
File::Find module, and Python’s
module provides some handy functions for manipulating files. For
renameWith provides procedural renaming: given a file name,
it applies a function to it, then renames the file to that name.
Here’s how you might use it to change your naming convention for C++
find always (extension ==? ".cpp") >>= mapM_ (renameWith (replaceExtension "C"))
modifyWithBackup functions edit a file in
place (the latter saves the original copy to a procedurally-renamed
backup file), so that you can more easily write
modifyInPlace (map toUpper) "shouting.txt"
Least interesting, but nonetheless useful, is
a glob pattern matching module. I wrote this because Haskell doesn’t
provide a standard one, and the only other one I know of (in the
MissingH library) goes through the regexp machinery. Ew.
darcs get http://darcs.serpentine.com/filemanip/