Article ID: 68268 - Last Review: May 12, 2003 - Revision: 2.0

Simulating Wildcards

This article was previously published under Q68268
Expand all | Collapse all

SUMMARY

You can simulate wildcards with the FOR command for those commands in MS-DOS that do not allow wildcards. The structure of the command is as follows
   for %p in (set) do (command) %p
				
where %p is a variable used by the FOR command, (set) is a set of filenames that command will be applied to, and command is the command to be carried out. 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 be much shorter. However, unlike the command-line version of the FOR command, the batch-file version uses two percent signs (%). The following are two batch-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 the MS-DOS prompt finds every file ending with the .TXT extension that has the string "CONFIG" in it. The quotation marks ("%2") are specific to the FIND command and not necessarily part of the FOR command syntax. If the second example is in a batch file called FF.BAT, to invoking the batch-file command, type:
   ff *.txt CONFIG"
				

APPLIES TO
  • Microsoft MS-DOS 3.1
  • Microsoft MS-DOS 3.2 Standard Edition
  • Microsoft MS-DOS 3.21 Standard Edition
  • Microsoft MS-DOS 3.3 Standard Edition
  • Microsoft MS-DOS 3.3a
  • Microsoft MS-DOS 4.0 Standard Edition
  • Microsoft MS-DOS 4.01 Standard Edition
  • Microsoft MS-DOS 5.0 Standard Edition
  • Microsoft MS-DOS 5.0a
  • 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
Keywords: 
KB68268
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
 

Article Translations