Metacharacters are characters that can be used to represent placeholders in a file name. The asterisk (*) and the question mark (?) are the two metacharacters.
The asterisk matches one or more characters, including blanks.
The question mark matches exactly one character, unless that character is a period. To match a period, the original name must contain a period. Metacharacters are illegal in all but the last component of a path.
Metacharacters are also referred to as global file name characters, or as wildcard characters.
An application that allows more than one file name on its command line, can accept metacharacters to provide users with a shortcut for entering a long list of names. For instance, metacharacters can be used to reference a set of files with a common base name; to reference all files with an extension of EXE, the user would enter:
*.exe
Although a name that contains metacharacters is not a complete file name, an application can use functions, such as DosFindFirst and DosEditName, to expand the name (replace the metacharacters) and create one or more valid file names.
Metacharacters have two sets of semantics:
Search metacharacters are used in commands that search for files or groups of files, like DIR:
dir *.exe
An application can expand a name with metacharacters to a list of file names by using DosFindFirst and DosFindNext. These functions take a file name template (a name with metacharacters) and return the names of files on the disk that match the pattern in the template.
Edit metacharacters are used in commands that can change the names of files; for example, in a global copy command:
copy *.txt *.old
An application can create a new file name from an existing name by using the DosEditName function. This function takes a template (a name with metacharacters) and expands it, using characters from an existing name. An asterisk in the template directs the function to copy all characters in the existing name until it locates a character that matches the character following the asterisk. A question mark directs the function to copy one character, unless that character is a period. The period in the template directs the function to look for and move to the next period in the existing name, skipping any characters between the current position and the period.