To Temple College Class  logo R. Craig Collins > ITSC 1305 > Wildcards

Wildcards © R. Craig Collins, 2005/7

A wildcard can be used when a DOS command should be applied to multiple files.

*, the asterisk (computer people call it star)
   can mean anything, or nothing, and range over multiple characters in a filename.

?, the question mark
   can mean something, for a specific character position in a filename.

Short examples

If you have the following files

text.ltr
text.txt
test1.txt
text2.txt
text10.txt


In order to copy, delete, or rename any file as long as it ends with .txt you would use
*.txt which could be read as anything.txt, or any file as long as it ends with .txt

If you use a wildcard in the source you must use the same wildcard pattern in the destination.

If you have the following files

text.ltr
text.txt
test1.txt
text2.txt
text10.txt


In order to copy, delete, or rename any file as long as it starts with text, and ends with anything,
you would use
test*.* which could be read as a file that starts with T E S T and then something else
OR nothing else
,
with any extension.

If you use a wildcard in the source you must use the same wildcard pattern in the destination.

If you have the following files

text.ltr
text.txt
test1.txt
text2.txt
text10.txt


In order to copy, delete, or rename any file as long as it starts with text plus one additional character,
and ends with anything,
you would use
test?.* which could be read as a file that starts with T E S T and has ONE additional character,
with any extension.

This would ignore test.txt, test.ltr, and test10.txt because they either have no 5th character, or have an additional 6th character not detailed in the statement.

If you use a wildcard in the source you must use the same wildcard pattern in the destination.


More detailed examples

Scenario:
A:\
   file.txt
   file1.txt
   file2.txt
   file3.txt
   file4.txt
   file10.txt
   fred.txt
   file.doc
   file1.doc
   file2.doc
   file3.doc
   file4.doc
   file10.doc
   fred.doc

If you wished to select any file, as long as it ends with .txt you would use:
*.txt (could be read anything.txt)
This would select
   file.txt
   file1.txt
   file2.txt
   file3.txt
   file4.txt
   file10.txt
   fred.txt
but not any file that ends with .doc

If you wished to select any txt file, as long as it starts with file you would use:
file*.txt (could be read fileanything.txt)
This would select
   file.txt
   file1.txt
   file2.txt
   file3.txt
   file4.txt
   file10.txt
but not
   fred.txt or any file that ends with .doc

Scenario:
A:\
   file.txt
   file1.txt
   file2.txt
   file3.txt
   file4.txt
   file10.txt
   fred.txt
   file.doc
   file1.doc
   file2.doc
   file3.doc
   file4.doc
   file10.doc
   fred.doc

If you wished to select any file, as long as it starts with the letters file you would use:
file*.* (could be read file anything with any extension)
This would select
   file.txt
   file1.txt
   file2.txt
   file3.txt
   file4.txt
   file10.txt
   file.doc
   file1.doc
   file2.doc
   file3.doc
   file4.doc
   file10.doc

but not
   fred.txt
   fred.doc

Scenario:
A:\
   file.txt
   file1.txt
   file2.txt
   file3.txt
   file4.txt
   file10.txt
   fred.txt
   file.doc
   file1.doc
   file2.doc
   file3.doc
   file4.doc
   file10.doc
   fred.doc

If you wished to select any text file, as long as it includes a single digit number you would use:
file?.txt (could be read file something if only in space number 5.txt)
This would select
   file1.txt
   file2.txt
   file3.txt
   file4.txt
but not
   file.txt (no 5th character in the filename) or
   file10.txt (? works only for space 5, not space 6)
or any file that ends with .doc

If you wished to select any file, with any extension, (all) you would use:
*.* (could be read any file with any extension)