3

Files in folder:

a.j
ab.jp
abc.jpg
abcd.jpeg

dir command results:

Command       Result (Files shown)
----------    --------------------
dir ?.*       a.j
dir ??.*      a.j, ab.jp
dir ???.*     a.j, ab.jp, abc.jpg
dir ????.*    a.j, ab.jp, abc.jpg, abcd.jpeg

So we can see single ? it means "0 or 1 letter".

Now more dir command results:

Command       Result (Files shown)
----------    --------------------
dir *.?       a.j
dir *.??      a.j, ab.jp
dir *.???     a.j, ab.jp, abc.jpg, abcd.jpeg --> What is this?!
dir *.????    a.j, ab.jp, abc.jpg, abcd.jpeg

In 3rd command why ??? is showing jpeg? Can you explain? Is this bug in cmd?

Kevin Panko
  • 7,466

3 Answers3

7

That's happening because the three question marks match the extension for the short version of the filename. Use

dir /x

to show (and work with) short versions of filenames.

Kevin Panko
  • 7,466
boot13
  • 5,917
2

Concerning the problem of extensions longer than three characters: This is caused by the way how short file names are created. You can solve this by setting Win95TruncatedExtensions in the registry:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
"Win95TruncatedExtensions"=dword:00000000

Specifies whether NTFS and FAT generate file names for new files with the 8.3 naming convention.

Setting the value of this entry to 1 does not change any existing file name extensions, nor does it change the way these extensions are displayed or managed by Find, File Manager, or Windows Explorer. However, it causes NTFS and FAT to generate short names for new files, and to truncate the third character of file name extensions.

Default value is 1

enter image description here

But keep in mind this will effect only newly created or copied files.

(you might copy all files on your hard disk. You should do this registry setting as one of the first action when installing a Windows system.)

nixda
  • 27,634
Konrad
  • 216
1

The command prompt uses the short filename system. That means that when a file has more than 8 characters before the point, the first 6 will be used + ~1. The same applies for when you use 4 chars or more behind the . It will then use the first 3 chars of the extension, and name the file differently (first 6 + ~1). So a .jpeg file is being seen to the command prompt as ??????~1.jpe and as such it will match *.???

Use dir /x to see files with their short filename.

LPChip
  • 66,193