BSD-3-Clause licensed by Neil Mitchell, Evan Rutledge Borden
Maintained by Neil Mitchell
This version can be pinned in stack with:filepattern-0.1.3@sha256:372c1733d83b90045eb29da9f010fed79bfef8771ce65eb126a1d83ecc54a9a2,2454

Module documentation for 0.1.3

Used by 5 packages in nightly-2024-11-29(full list with versions):

FilePattern Hackage version Stackage version Build status

A library for matching files using patterns such as src/**/*.png for all .png files recursively under the src directory. 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.

More complete semantics are given in the documentation for the matching function ?==.

Features

  • All matching is O(n). Most functions precompute some information given only one argument. There are also functions to provide bulk matching of many patterns against many paths simultaneously, see step and matchMany.
  • You can obtain the parts that matched the * and ** special forms using match, and substitute them into other patterns using substitute.
  • You can search for files using a minimal number of IO operations, using the System.FilePattern.Directory module.

Related work

  • Another Haskell file pattern matching library is Glob, which aims to be closer to the POSIX glob() function, with forms such as *, ?, **/ (somewhat different to the filepattern equivalent) and [:alpha:]. A complete guide is in the documentation. Compared to filepattern, the Glob library is closer to a regular expression library - definitely more powerful, potentially harder to use.
  • The shake library has contained a FilePattern type since the beginning. This library evolved from that code, with significant improvements.
  • The semantics are heavily inspired by VS Code, Git and the NPM package Glob.

Changes

Changelog for filepattern

0.1.3, released 2022-08-21
#5, remove invalid optimisation in the presence of symlinks
0.1.2, released 2020-02-26
Optimise matchMany for empty lists
Remove support for GHC 7.4 to 7.8
Make Directory module reexport FilePattern
0.1.1, released 2019-02-12
Switch to https://github.com/ndmitchell/filepattern
0.1, released 2019-02-12
Substantial (almost total) rewrite
Remove // patterns
Split from shake-0.16