Warning about *.doc and other wildcards for Office documents.

Office for Mere Mortals helps people around the world get more from Word, Excel, PowerPoint and Outlook. Delivered once a week. free.

Will R. an Office-Watch.com reminded us of a trap when dealing with .doc and .docx files.

I opened a command prompt and did a del *.doc. Imagine my surprise when it deleted both .doc and .docx files (I have backups). 

Firstly, a teacher’s gold star plus wise owl stamp to Will for having backups!

Yes, it’s a trap when dealing with any wildcards in the Command Prompt/DOS box or Windows Explorer.  Any additional characters in the file extension are INcluded in the results.

Any wildcard like  *.xls  is treated as *.xls*  and will include any extension starting with  xls

This applies to both the command prompt (aka DOS box) or Explorer.

It’s a hold over from the olden days when Windows and DOS were limited to three character extensions.

Quotes workaround

The safest workaround is to be in the habit of using quotes around wildcards.

Always put quote marks around wildcards to ensure Windows only selects the intended files.

For example,  "*.doc"  will only select files with that three letter extension and no more.

Same goes for  "*.xls"    "*.ppt" , naturally.


Will notes that PowerShell behaves differently with *.doc only getting the three letter extension.

Want More?

Office Watch has the latest news and tips about Microsoft Office. Independent since 1996. Delivered once a week.