|An interesting question on two counts:|
1. Why is *.doc matching, e.g., file.doc1?
2. How to avoid the problem?
That 1 is indeed the case can be seen by doing:
in a directory containing files 1.doc, 1.doc1, and 1.doc2. The output will be:
Why should that happen? (It doesn't if you type "dir *.do"). I believe the answer lies in the short filenames (8.3 format) that Windows automatically creates. For example, for "1.doc1" there will also be a short filename something like "17126~1.doc". You can see these short names by adding the /X switch to the dir command.
The solution? Try instead:
forfiles /m *.doc /c "cmd /c echo @file"
and you will only get:
The "forfiles" command seems to only match the full filename. So the answer is to use the command:
forfiles /s /m *.doc /c "cmd /c del @file"
either from the command line or in a batch file.
Until your question I never appreciated this behaviour of wildcard matching in some commands. You learn something new every day.