HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulefilepattern-0.1.3Haskell2010

System.FilePattern

A module for matching files using patterns such as "src/**/*.png" for all .png files recursively under the src directory. See ?== for the semantics of FilePattern values. Features:

  • All matching is O(n). Most functions precompute some information given only one argument.

  • Use match and substitute to extract suitable strings from the * and ** matches, and substitute them back into other patterns.

  • Use step and matchMany to perform bulk matching of many patterns against many paths simultaneously.

  • Use System.FilePattern.Directory to perform optimised directory traverals using patterns.

  • 3 types
  • 7 values
  • Packagefilepattern-0.1.3
  • Exports10
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceFilePattern.hs
typetype FilePattern = String
#

A type synonym for file patterns, containing ** and *. For the syntax and semantics of FilePattern see ?==.

Most FilePath values lacking literal . and .. components are suitable as FilePattern values which match only that specific file. On Windows \ is treated as equivalent to /.

You can write FilePattern values as a literal string, or build them up using the operators <.> and </> (but be aware that "" </> "foo" produces "./foo").

value(?==) :: FilePattern -> FilePath -> Bool
#

Match a FilePattern against a FilePath. There are two special forms:

  • * matches part of a path component, excluding any separators.

  • ** as a path component matches an arbitrary number of path components.

Some examples:

  • test.c matches test.c and nothing else.

  • *.c matches all .c files in the current directory, so file.c matches, but file.h and dir/file.c don't.

  • **/*.c matches all .c files anywhere on the filesystem, so file.c, dir/file.c, dir1/dir2/file.c and /path/to/file.c all match, but file.h and dir/file.h don't.

  • dir/*/* matches all files one level below dir, so dir/one/file.c and dir/two/file.h match, but file.c, one/dir/file.c, dir/file.h and dir/one/two/file.c don't.

Patterns with constructs such as foo/../bar will never match normalised FilePath values, so are unlikely to be correct.

valuematch :: FilePattern -> FilePath -> Maybe [String]
#

Like ?==, but returns Nothing on if there is no match, otherwise Just with the list of fragments matching each wildcard. For example:

isJust (match p x) == (p ?== x)
match "**/*.c" "test.txt" == Nothing
match "**/*.c" "foo.c" == Just ["","foo"]
match "**/*.c" "bar/baz/foo.c" == Just ["bar/baz/","foo"]

On Windows any \ path separators will be replaced by /.

Multiple patterns and paths

5 declarations
valuestep :: [(a, FilePattern)] -> Step a
#

Efficient matching of a set of FilePatterns against a set of FilePaths. First call step passing in all the FilePatterns, with a tag for each one. Next call the methods of Step, providing the components of the FilePaths in turn.

Useful for efficient bulk searching, particularly directory scanning, where you can avoid descending into directories which cannot match.

datadata Step a
#

The result of step, used to process successive path components of a set of FilePaths.

Constructors

Instances3Functor, Semigroup, Monoid
  • Functor StepDefined in filepattern-0.1.3 · System.FilePattern.Step
  • Semigroup (Step a)Defined in filepattern-0.1.3 · System.FilePattern.Step
  • Monoid (Step a)Defined in filepattern-0.1.3 · System.FilePattern.Step
datadata StepNext
#

What we know about the next step values.

Constructors

Instances5Eq, Ord, Show, Semigroup, Monoid
  • Eq StepNextDefined in filepattern-0.1.3 · System.FilePattern.Step
  • Ord StepNextDefined in filepattern-0.1.3 · System.FilePattern.Step
  • Show StepNextDefined in filepattern-0.1.3 · System.FilePattern.Step
  • Semigroup StepNextDefined in filepattern-0.1.3 · System.FilePattern.Step
  • Monoid StepNextDefined in filepattern-0.1.3 · System.FilePattern.Step
valuematchMany :: [(a, FilePattern)] -> [(b, FilePath)] -> [(a, b, [String])]
#

Efficiently match many FilePatterns against many FilePaths in a single operation. Note that the returned matches are not guaranteed to be in any particular order.

matchMany [(a, pat)] [(b, path)] == maybeToList (map (a,b,) (match pat path))