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 rm *.tmp, del *.tmp
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"
(Replace %f with %%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.
https://docs.microsoft.com/en-us/archive/blogs/josebda/windows-server-2012-file-server-tip-disable-8-3-naming-and-strip-those-short-names-too
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
or run 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
Note that 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
del *.tmpshould only delete files with the.tmpfile exttension that exist within the directory the command was issued in. – Ramhound Apr 26 '21 at 14:44file.exe *.txtpasses the raw*.txtstring to the file.exe. Windows also doesn't split arguments and the program must parse its own command line to get the list of tokens. In reality the C runtime does that for you – phuclv Apr 27 '21 at 16:51project.tmplhas the "8.3" namePROJEC~1.TMP. The Windows API provides a function (SetFileShortName()) that allows changing (renaming) the "8.3" file name of a file without changing the "long" name. So your file might still be namedproject.tmplbut the "8.3" name may beproject.tplinstead ofprojec~1.tmp. Unfortunately, I didn't find out if there is a "ready" command line command or if you'd have to write a short C/C++ program to do this... – Martin Rosenau Apr 28 '21 at 09:28fsutilhas everything you need.fsutil file setshortnamewill change the name to your desired one.fsutil 8dot3name stripwill remove all short names – phuclv Apr 28 '21 at 09:40It's a general programming term. And yes windows doesn't do wildcard expansion on the shell. I also never claimed it did. I was describing the behavior of the wildcard of the standard windows utility commands. They do their own wildcard expansion. Wildcard expansion is often referred to as globbing. Nothing I said is controversial. Dont at me again.
– Tim Seguine Apr 30 '21 at 14:08