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. The 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 entirely backwards compatible with filesystem globbing, except for one nuance. For example, patterns **/*.txt and c:/**/a.txt behave exactly the same. There is only one tiny difference. The pattern **.txt means recursive traversation as an Asterisk Pattern, but as a glob it means files only from current folder (the same as *.txt). Unlike in glob, the ** always means recursiveness in Asterisk Patterns. Asterisk Patterns maintain consistency.
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.