Simulating Wildcards

This article was previously published under Q68268
This article has been archived. It is offered "as is" and will no longer be updated.
Summary
You can simulate wildcards with the FOR command for those commands inMS-DOS that do not allow wildcards. The structure of the command is asfollows
   for %p in (set) do (command) %p				
where %p is a variable used by the FOR command, (set) is a set of filenamesthat command will be applied to, and command is the command to be carriedout. For example:
   for %p in (*.txt) do type %p				
-or-
   for %p in (*.txt) do find "CONFIG" %p				
More information
You may want to create a batch file for this command because it will bemuch shorter. However, unlike the command-line version of the FOR command,the batch-file version uses two percent signs (%). The following are twobatch-file examples:
   for %%p in (%1) do type %%p				
-or-
   for %%p in (%1) do find "%2" %%p				
Using the second batch-file example, the following command typed at theMS-DOS prompt finds every file ending with the .TXT extension that has thestring "CONFIG" in it. The quotation marks ("%2") are specific to the FINDcommand and not necessarily part of the FOR command syntax. If the secondexample is in a batch file called FF.BAT, to invoking the batch-filecommand, type:
   ff *.txt CONFIG"				
6.22 3.x 4.00 4.01 5.00 5.00a 6.00 6.20 wild card
Properties

Article ID: 68268 - Last Review: 10/26/2013 13:35:00 - Revision: 3.0

  • Microsoft MS-DOS 4.0 Standard Edition
  • Microsoft MS-DOS 5.0 Standard Edition
  • Microsoft MS-DOS 6.0 Standard Edition
  • Microsoft MS-DOS 6.2 Standard Edition
  • Microsoft MS-DOS 6.21 Standard Edition
  • Microsoft MS-DOS 6.22 Standard Edition
  • kbnosurvey kbarchive KB68268
Feedback