Wild Cards

Q3. What are wild cards? What is the use of’?’ and ‘*’ wild cards?

Ans. Two special characters, ‘?’ (question mark) and ‘*’ (asterisk) are called wildcards in DOS. They are useful in MS-DOS command lines because they give flexibility in specifying paths and files.

 

The ? Wild Card

A question mark (?) in a filename or file anme extension means that any one or more character can occupy that position. For instance,

Memo?.doc     would represent

Memodoc

Memo3.doc

Memo4.doc

Memo7.doc

Memo9.doc and so on

that is, any file starting with memo following by exactly any one or none character and with an extension .doc.

Please remember when ? is the last character in the primary or secondary name pattern, then it goes for the one or none character matching otherwise it goes for exactly one character matching.

If we have following sample list of files on the disk:

Ab.exe

Abc.exe

Ans.exe

Answer.exe

Ans2.exe

Aug.doc

Batch.dat

Bc.exe

Bye.doc

Bbc.exe

Then    ?bc.exe will give

Abc.exe

Bbc.exe

That is any one character followed by bc and extension, .exe. See bc.exe is not included as it didn’t go for none character match.

Similarly A??.exe will list

 

Ab.exe

Abc.exe

Ans.exe

 

because A??.exe means A followed by any two or less characters and extension .exe.

 

 

The * Wildcard

The * (asterisk) replaces any number of characters. Using the above sample list, A*.exe will list

 

Ab.exe

Abc.exe

Ans.exe

Answer.exe

Ans2.exe

 

As A*.exe means A followed by any number of characters (but length should not exceed eight in number) and extension .exe.

 

Similarly, B*.* will list all files starting with B.

 

Bc.exe

Batch.dat

Bat.dat

Bye.doc

Bbc.exe

 

*.doc will list

 

Aug.doc

Bye.doc

 

*.doc means any primary name with extension doc.*.* can be used for referring all files with any primary name and any extension.

 

These two wildcards can be used together also. For instance, B*.ex? will list

 

Bc.exe

bag.ex2

Bbc.exe

 

From the above sample list as B*.ex? means files with primary names starting with B and extension starting with ex followed by any one ot none character.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s