A file may have short DOS 8.3 names and all internal commands from DOS era also work with both long and short name for compatibility reasons1 so a file with long extension may be accidentally matched. There are many similar questions:
It'd be better to use PowerShell because short names aren't matched anymore.
dir in cmd must match the short names in order to not break legacy programs. PowerShell doesn't have that limitation. Just run
Remove-Item *.tmp or any of its aliases like
In cmd you'll have to filter with
findstr like this
for /F "delims=" %f in ('dir /B ^| findstr /I /E ".tmp"') do @del "%f"
%%f in a batch file)
There are also many other solutions such as
forfiles (as that's not a cmd's internal command) that you can find in How can I get the "dir" and "copy" commands to operate on "*.xyz" but not "*.xyz~"?
However it'll be even better to disable 8.3 name generation and remove all the short names. In fact since Windows 8 and Windows Server 2012 newly formatted volumes will have 8.3 name generation disabled by default for performance reasons. That'll also help avoid situations like this: WinXP dir command: 3 and 4 char extensions are the same?
In fact, recent versions of Windows Server don’t even enable 8.3 naming when you format new data volumes.
If your drive still has 8.3 name generation enabled then run the following command to disable it on drive C:
fsutil 8dot3name set C: 1
fsutil 8dot3name set 1 to disable it on all volumes
The setting can also be set in registry. The corresponding key is
HKLM\System\CurrentControlSet\Control\FileSystem\NtfsDisable8dot3NameCreation. The value for the
fsutil and the registry key is like this
- 0: Enables 8dot3 name creation for all volumes on the system.
- 1: Disables 8dot3 name creation for all volumes on the system.
- 2: Sets 8dot3 name creation on a per volume basis.
- 3: Disables 8dot3 name creation for all volumes except the system volume.
If the names are there it can also be removed with
fsutil 8dot3name strip
fsutil must be run with admin privileges
1Old commands list their files using the old
FindFirstFile API which matches both long and short names. See Why does
FindFirstFile find short names?. New code should use
FindFirstFileEx instead to avoid that