Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
WinXP dir command: 3 and 4 char extensions are the same?

I have been annoyed by a strange behavior of cmd.exe for a long time (at least WinXP and Windows7). A command like del *.txt will also remove *.txt1 files (any number of characters after '.txt' will do). Is this a well known bug or what?

share|improve this question

migrated from Jul 4 '11 at 10:16

This question came from our site for professional and enthusiast programmers.

marked as duplicate by random Jun 18 '12 at 21:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 8 down vote accepted

It's an occasionally-encountered somewhat-known?

An explanation of the behavior is here, complete with a possible work-around.

Summary: It comes from the way NTFS handles short (8.3) filenames, for compatibility with older stuff that can't handle "new-fangled" long filenames. dir /x can be used to view the short filename, like so:

C:\>dir /x *~*
02/25/2011  08:18 AM    <DIR>          DOCUME~1     Documents and Settings
05/28/2011  12:02 AM    <DIR>          PROGRA~1     Program Files

Extensions longer than three characters will simply be truncated for their short filename; so .txt1, .txtxtxtxt, .txt_file, etc, all become .txt.

share|improve this answer
+1 for the link – Mehrdad Jul 4 '11 at 5:38

Files with more than 4 letters in the extension (and other rules of course also apply), get a short name, so for example "foo.txt1" has the shortname "foo~1.txt". DEL (like DIR and possibly most other cmd.exe builtin commands) will also operate on shortnames. For a discussion on a related topic see here:

share|improve this answer
+1 for a more authoritative link than mine. – Jim Davis Jul 4 '11 at 5:39

Would this be on a FAT/VFAT filesystem? If so, you're getting bitten by the hackery used to represent names that don't fit into the 8.3 schema; there's a DIR option that shows you the mangled short names, which will begin with the actual file name but have a ~ and a number before the extension, then the extension is capped at 3 characters. (Example: C:\Program Files usually translates to C:\PROGRA~1.) A wildcard may unexpectedly match these names. This should not happen on NTFS or (I think) on network shares. except that DOS still hasn't died, it seems....

share|improve this answer

You can probably use "Forfiles" command for a workaround

Eg. Forfiles -s -m *.txt -c "cmd /C del /q @path"

Matches only "txt" endings.

share|improve this answer