wildcard : Java Glossary

In Windows BAT (Batch) language you can refer to all files in a directory as
*.html or all files a?.html for all
two-letter files starting with a. The way you specify such a group of files is called
a wildcard. * matches any string. ? matches any single character.

Windows

Using cmd.exe as the command processor, or
Take Command tcc.exe, wildcards behave in a way that may
surprise you.

cert*.html ⇒ a list of the files matching the
pattern. Your Java program does not need to expand the wild card itself. It does
not see the wildcard; it sees only a list of files that match the pattern at its
main ( String[] args ) This happens for Java only, it does not happen for C/C++ or assembler
utilities.

silly*.html ⇒ silly*.html since there were no matches.

cert*.html ⇒
cert*.html, with the quotes stripped off, even though
there were matches, suppresses wildcard expansion.

cert *.html ⇒
cert *.html, with the quotes stripped off, even though
there were matches, suppresses wildcard expansion.

IntelliJ Idea under Windows

Using the IntelliJ Idea
IDE (Integrated Development Environment) to run programs, wildcards behave in a way that may
surprise you.

cert*.html ⇒ a list of the files matching the
pattern.

silly*.html ⇒ silly*.html since there were no matches.

cert*.html ⇒ a list
of the files matching the pattern. I think this is a
bug.

I tried to fix the problem by quoting the * with cert\*.html. It treated the \ literally, decided there were
matches and returned cert\*.html, with the quotes
stripped off, not that useful.

cert *.html ⇒
cert *.html, with the quotes stripped off, even though
there were matches, suppresses wildcard expansion.

Bash under Linux

Using bash as the script processor,
wildcards behave in a way that may surprise you.

cert*.html ⇒ a list of the files matching the
pattern.

silly*.html ⇒ silly*.html since there were no matches.

'cert*.html' ⇒ cert*.html, with the apostrophes stripped off, even though there
were matches.

I am also told in Linux/bash you can subvert the globbing with \ quoting, e.g. \*.html Then
your program will get the command-line parameters unexpanded. See parameter expansion in bash for more details.

Experiment!

It is probably easier to understand this by experiment than by
explanation. Here is a simple tool to help you.

Converting Wildcards to Regexes

You can convert a wild card

Summary

This wildcard expansion mechanism is Mikey Mouse. It does not work
for wildcards containing spaces. It is confusing for wildcards without matches. It
makes it difficult to pass * or ?
as data. I think the best way out is for Sun to provide an alternate mechanism to
passing the entire command line completely unmodified.