Wildcards - DOS/Command Prompt Reference
A wildcard consists of the characters ‘*’ and ‘?’, and is used in combination with general strings (such as letters and numbers). It is employed when searching for files, for example, when you don't know part of a file name or when you want to retrieve a list of files with the same pattern.
Characters
? |
Represents ‘any single character’. For example, in ‘ho?e’, it would match ‘hoge’, ‘hole’, ‘home’, ‘ho9e’, ‘ho_e’, and so on. [MS-DOS, Windows 95/98/Me] In a file name, ‘ho?e’ would match ‘ho.e’ as well, but ‘hoge.dt?’ would not match ‘hoge.dt’. However, ‘hoge?’ would match ‘hoge’. [Windows NT/XP or later] In a file name, ‘ho?e’ does not match ‘ho.e’, but ‘hoge.dt?’ matches ‘hoge.dt’, and ‘hoge?’ matches ‘hoge’. |
* | Represents ‘any string of length 0 or more’. For example, in ‘win*’, it would match ‘win’, ‘wind’, ‘windows’, ‘wing’, ‘wins’, ‘win.com’, and so on. |
Note that a simple replacement in regular expressions would be ‘?’ → ‘.’ and ‘*’ → ‘.*’ (there may be subtle differences).
Notices
- Wildcards are not supported in all commands. Please refer to the explanation for each command for more details.
- The wildcard characters ‘*’ and ‘?’ cannot be used in file names or directory names. (Therefore, it is not possible to search for file names that contain ‘*’ or ‘?’.)
Samples
Sample 1
dir *. /w
Displays all files without extensions, including directory names that do not contain ‘.’.
* Executing this command will display file names that start with ‘.’, as well as those that do not contain ‘.’ at any other position.
Sample 2
for %1 in (*.*_) do expand.exe %1
Using the For command, performs the execution of ‘expand.exe’ for each file with an extension ending in ‘_’ by using them as individual arguments.
Sample 3 (Batch file)
md \Backup copy *.in? \Backup
Copy all files with a three-character extension where the first two characters of the extension are ‘in’ (e.g. ‘setup.ini’ and ‘driver.inf’) to the directory ‘\Backup’.