It’s all very well to have a function that
can match glob patterns, but we’d like to be able to put this to
practical use. On Unix-like systems, the
glob function returns the names of all files
and directories that match a given glob pattern. Let’s build a similar
function in Haskell. Following the Haskell norm of descriptive naming,
we’ll call our function
-- file: ch08/Glob.hs module Glob (namesMatching) where
We specify that
namesMatching is the only name that users of
Glob module will be able to see.
This function will obviously have to manipulate filesystem paths a lot, splicing and joining them as it goes. We’ll need to use a few previously unfamiliar modules along the way.
System.Directory module provides standard
functions for working with directories and their contents:
-- file: ch08/Glob.hs import System.Directory (doesDirectoryExist, doesFileExist, getCurrentDirectory, getDirectoryContents)
System.FilePath module abstracts the details
of an operating system’s path name conventions. The
(</>) function joins two path
"foo" </> "bar"Loading package filepath-126.96.36.199 ... linking ... done. "foo/bar"
The name of the
dropTrailingPathSeparator function is
splitFileName function splits a path at the
splitFileName "zippity"("","zippity") ...