“treesum” Filter Patterns¶
Description¶
Filename matching allows several types of patterns. Each pattern should start with its type specification.
glob:POSIX glob() style, case-sensitive, anchored at the begin and end
iglob:case-insensitive variant of
glob
re:regular expression (Python style)
path:plain path name (rooted), can be a file or a directory or a prefix thereof
fullpath:exactly a single full path (file or directory), relative to the root of the tree
If a type is not given explicitely glob: is assumed.
Important
Pattern matching is done using paths relative to the root of the directory tree.
Patterns with absolute paths—while syntactically allowed—never match in py-treesum.
The directory separator is always
/.
Todo
Encoding used for pattern matching. Also make it more consistent.
Glob Syntax Rules¶
The
*character matches zero or more characters of a name component without crossing directory boundaries.The
**characters matches zero or more characters crossing directory boundaries.**/matches zero or more subdirectories; files do not match.The
?character matches exactly one character of a name component.The backslash character (
\) is used to escape characters that would otherwise be interpreted as special characters. The expression\\matches a single backslash and\{matches a left brace for example.The
[ ]characters are a bracket expression that match a single character of a name component out of a set of characters. For example,[abc]matchesa,b, orc. The hyphen (-) may be used to specify a range so[a-z]specifies a range that matches fromatoz(inclusive). These forms can be mixed so[abce-g]matchesa,b,c,e,forg.If the character after the
[is a!then it is used for negation so[!a-c]matches any character excepta,b, orc.Within a bracket expression the
*,?and\characters match themselves.The
-character matches itself if it is the first or last character within the brackets, or the first or last character after the!if negating.Also, the
]character matches itself if it is the first character within the brackets, or the first character after the!if negating.The curly brace characters
{ }denote a group of subpatterns, where the group matches if any subpattern in the group matches.The
,character is used to separate the subpatterns. Groups can be nested.Leading period/dot characters in file name are treated as regular characters in match operations. For example, the
*glob pattern matches file name.login.All other characters match themselves.
Examples¶
glob:*.pyany name ending with
.pyin the root directory
*.pythe same as
glob:*.py(becauseglob:is the default)
re:\A[^/]*\.py\Zthe same as
glob:*.py
glob:**.pyany name ending with
.pyanywhere
re:\.py\Zthe same as
glob:**.py
glob:dir/*any name in directory
dir
Each of these patterns specify any name below directory dir:
glob:dir/**
re:\Adir/
path:dir/
Each of these patterns specify any name in any directory that ends with
file:
glob:**/file
re:(^|/)file\Z
These patterns specify a single path:
filepath:dir1/dir2/file
re:\Adir1/dir2/file\Z