How to use MS-DOS Wildcard Characters

How to use MS-DOS Wildcard Characters

Overview

How would you do it with DOS? You could use DIR over and over in different directories until you find the files. Then you could use COPY (the command for copying files) over and over until each file was copied. It would be really boring and very time-consuming. Or, you could use wildcards! DOS has two wildcard characters that you can use to get your commands to work on a group of files. Instead of on one file at a time.

These DIR and COPY commands are DOS Internal Commands.

Wildcard characters work pretty much like wild cards in poker, Crazy Eights, and other card games. A card, or in this case a character, is designated as being “wild.” That means it can stand for any other card or character. The wildcard characters in DOS are the asterisk (*) and the question mark (?).

The question mark replaces just one character at a time

The question mark (?) can replace any one character in a file name. To see how it works, start by changing to a directory with lots of files in it. Goto “RUN” and type cmd then open the window of command prompt.

On drive C:, type:

C:/> cd \dos                  <enter>

Then try this command:

C:/> dir mo?e.txt         <enter>

DIR is the command, followed by one space. Everything else is one word, entered without spaces. DOS should show you all the files in the \DOS directory that start with MO and end in E, and have a TXT extension. I got the two file names to show below, MORE.TXT and MODE.TXT.

Let’s try another one:

C:/> dir ?2???.txt <enter>

DOS should pick out files that have five-letter names with a 2 the second character, and the extension TXT. Show in below:

Tip:

Wild cards are not just for the DIR commands, they also work with commands that delete, copy, move, and rename files, as you will see next DOS blogs.

The asterisk can stand for a bunch of characters  

DOS has another wildcard, potentially even more powerful than the question mark (?). When you want to work with a larger group of files, you can use the asterisk (*) in your commands. The asterisk is used to replace several characters at once. For example, if you wanted to see all the TXT files in your DOS directory, you could type:

C:/> dir *.TXT     <enter>

The asterisk represents every possible character in the file name. So, DOS finds all files with a TXT extension. The list is shown below:

To see all files that start with the letter M, no matter what their extensions (if any) are, type:

C:/> dir m*.*     <enter>

The file specification here says “Gimme an M! and I do not care what else.” My listing had 03 files in it, more than I could fit on the screen see below. The asterisk will accept anything, including no characters at all. If I had a file named just M (with no extension), the last command would have found that one, too.

“Many experienced users call the asterisk a star. When using wild cards with all files in a directory or on a drive, you type *.*, which is generally pronounced “star dot star.”

Tip:

A really neat way to use the * wild card is like this: *.*, which means all files and all extensions. Its quick way to get DOS to copy, move, or delete all the files on a disk or in a directory.

To get a better idea of how the asterisk wild card works, try the following directory commands in C:\DOS. Look at each one before you try it, and try to guess what files it will show. Then enter the command to see if you were right.

C:/>dir *.com                    <enter>

C:/>dir *.exe/p                 <enter>

C:/>dir *.*                          <enter>

C:/>dir dis*.*                     <enter>

C:/>dir dis*.com               <enter>


Leave a Reply

Your email address will not be published. Required fields are marked *

Back to Top
× How can I help you?

Warning: file_get_contents(index.php): failed to open stream: No such file or directory in /home/u230067725/domains/techfreshguru.com/public_html/wp-includes/plugin.php on line 437

Warning: file_get_contents(index.php): failed to open stream: No such file or directory in /home/u230067725/domains/techfreshguru.com/public_html/wp-includes/plugin.php on line 437

Warning: file_get_contents(index.php): failed to open stream: No such file or directory in /home/u230067725/domains/techfreshguru.com/public_html/wp-includes/plugin.php on line 437

Warning: file_get_contents(index.php): failed to open stream: No such file or directory in /home/u230067725/domains/techfreshguru.com/public_html/wp-includes/plugin.php on line 437