In short, do not expect this function to work like the command interpreter Cmd.exe. This function does not handle many boundary conditions, nor does it properly handle empty extensions.
The simplest example is this command, which correctly finds the Windows directory on all versions of Windows and MS-DOS 6.x:
dir c:\windows.*
However, this API call returns false on Vista:
BOOL b = ::PathMatchSpec("C:\\Windows", "C:\\Windows.*");
Other inconsistencies are shown in the table below. The "right" answer to these scenarios is unclear because MS-DOS did not support long filenames or spaces in filenames. Although various versions of Windows are themselves inconsistent, PathMatchSpec() does not agree with any of them. I would argue that the correct behavior is what Windows Vista does.
Command | ::PathMatchSpec("C:\\Windows", xxx); | MS-DOS | Win 9x | Win NT |
---|---|---|---|---|
dir c:\windows.* | False | Displays directory name | Displays directory name | Displays directory name |
dir c:\windows. | False | Displays directory contents | Displays directory contents | Displays directory contents |
dir c:\windows... | False | Displays directory name | Displays directory contents | Fail |
dir "c:\windows " (Note the trailing space) | False | n/a | Displays directory contents | Fail |
dir "c:\windows ." (Note the trailing space followed by a period.) | False | n/a | Displays directory contents | Fail |
And yes, I did actually install MS-DOS to create this chart :-)