Asterisk Patterns provide string pattern matching for files and directories by using only one special character: the asterisk *. They can be described simply (but not completely accurately) by the following two rules. The real detailed rules are at the bottom of this page.
1) Single asterisk * represents a sequence of characters without path separators (/ or \). 2) Double asterisk ** represents a sequence of characters that may contain path separators (/ or \).
Using an asterisk, the code above can be simplified to:
We can insert as many asterisks as we want. They can be placed even in the middle of a complex path. This is how we can visit multiple directories.
Double asterisks are an extension to the usual single asterisks, as they can also match path separators. For example, **.txt means all text files from the entire directory tree starting from current location.
Command below finds all files with name index.html on the F drive. They are then opened with the Notepad text editor. File f:/index.html is included if it is there.
Single asterisks and double asterisks can be put together into one pattern. Command below deletes all text files located at least two levels deep in the directory tree.
Asterisk Patterns match both files and directories. Restrictions can be imposed by the use of variables isFile and isDirectory.
Asterisk Patterns are almost entirely backwards compatible with filesystem globbing. For example, patterns **/*.txt and c:/**/a.txt behave exactly the same when applied as glob and as Asterisk Pattern. The differences are tiny and appear in rare special cases. Why introduce changes? Why not follow the convention already applied in various software as glob? Asterisk Patterns are more general, easier to understand and have fewer nuances. This is subjective point of view of the author. We can shorten the patterns, so instead of glob f:/**/*.txt, let there be just f:/**.txt.
Finally, here are 4 rules that govern Asterisk Patterns:
1) Single asterisk * represents empty space or a sequence of characters that does not contain path separators. 2) Double asterisk ** represents empty space or a sequence of characters that may contain path separators. 3) If double asterisk ** represents empty space, is not adjacent to a non-separator character and is adjacent to a separator on the right, then this separator can be omitted. 4) Both wildcards cannot represent characters restricted for file names nor drive letters.