[an error occurred while processing this directive] Node:Filename globbing, Next:, Previous:Command line, Up:Command line

16.1 Filename wildcards expansion under DJGPP

Q: Can I do filename globbing with DJGPP?

Q: I call my program with an argument x*y and it complains about something called xyzzy??....

Q: I cannot find a way to use the /? switch with my programs!

A: The filename globbing in DJGPP is done by the start-up code, before your main function is called. Unlike other DOS-based compilers, where you must link your program with a special object module if you want the program to get expanded filenames, in DJGPP this is considered normal behavior and is performed by default on behalf of every DJGPP program. The x*y above was expanded to a file called xyzzy which was probably present in the current working directory; and /? is by default expanded to the list of one-letter files/directories you happen to have in the root directory of the current drive. (If you don't want the default expansion, refer to how to disable globbing.)

In DJGPP, filename globbing works like in Unix, which is more general than the usual wildcard expansion, both in DOS and even in Windows. The DJGPP wildcard expansion understands the following constructs with special meta-characters:

?
any single character.
*
zero or more arbitrary characters, including a dot `.'
[aA_]
any one of characters `a', `A', or `_'.
[a-d]
any one of characters `a', `b', `c', or `d'.
[!a-z]
anything but a lowercase letter.
...
all the subdirectories, recursively (VMS aficionados, rejoice!).
.../*
all the files in all subdirectories, recursively.

Unlike DOS, the * and ? meta-characters can appear anywhere in the filename pattern, like in [a-z]*[0-9].*pp. You can also use * instead of directories, like in */*/*.c, but not on drive letters (e.g., [a-c]:/ won't work).

Note that *.* only picks up files that actually have an extension. This is contrary to the usual DOS practice where it means all the files, with or without extension. Use * to get files with and without extensions.

An argument which cannot be expanded (no filenames matching that particular pattern) will be passed to the program verbatim. This is different from what you might see under Unix, where some shells (like csh) would say something like "No match" and won't call your program at all. DJGPP's behavior in this case is like shells of the Bourne legacy (sh, ksh, and bash).

If the wildcards include upper-case or mixed upper- and lower-case letters, the letter-case of the files is not ignored on Windows 9X when expanding the wildcards. For example, [A-D]* will not match a file called aFileName. Upper-case letters in wildcards also disable automatic down-casing of short 8+3 file names returned by the code that expand wildcards (even on plain DOS). By contrast, if the wildcards include only lower-case letters, the letter-case is ignored during expansion, and short 8+3 file names are automatically down-cased, unless the environment variable FNCASE is set to y. The effect of setting FNCASE is fully described in the DJGPP C Library reference, under the _preserve_fncase function; type info libc alphabetical _preserve_fncase from the DOS prompt.


[an error occurred while processing this directive]