batch-file Bugs in cmd.exe processor DEL File Extension


Example

This bug was reported by steve2916 from this Microsoft Windows Forum thread.


Cause

Consider a folder with such files.

TestA.doc
TestB.doc
TestC.docx
TestD.docx

If we want to remove all .doc file in this directory, we usually would do:

del *.doc

However, this command also removes the .docx files. The same happens on file extensions with this pattern.

File AFile B
Anyname.abcAnotherName.abcd

As we can see, as long as the file extension string contains the string used in the del command, the file will be deleted. Note that this bug only occurs when the extension string used in the del command has at least three characters. For instance, del *.do doesn't delete A.doc or A.docx.

Solution

In the thread, user MicroCompsUnltd noticed that using Powershell would solve the issue.