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?

3
  • 3
    One has to ask one's self. What is more likely. A bug in a program that has not changed in functionality since it was first introduced or does one's self have a incorrect understanding how the command works?
    – Ramhound
    Commented May 27, 2015 at 19:06
  • @Ramhound: This might not be a bug, but surely you're not implying that cmd has no bugs? :) There are all sorts of weird edge cases and undocumented behaviour. It's old all right but barely been touched till Win10 which has added a few new cosmetic features, but I don't think the bugs have been fixed.
    – Karan
    Commented May 28, 2015 at 3:51
  • @Karan I never said there could be a bug just suggested not understanding how a feature worked is more likely considering command prompt has not changed in ages
    – Ramhound
    Commented May 28, 2015 at 3:57

3 Answers 3

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.

2
  • 1
    This seems to be the correct reason, which can be confirmed by using what snoopy wrote.
    – Karan
    Commented May 27, 2015 at 19:18
  • 1
    I'm sure that's the answer. I once typed dir and found that there were a couple of files that I wanted to remove with 1 at the end of the name, so I typed del ???????1.*, only to find that most of the files with long names were also deleted! Fortunately I keep copious back-ups, but it's a mistake one makes only once.
    – AFH
    Commented May 27, 2015 at 21:37
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.)

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.

2
  • dir /x shows .JPEG as .JPE, so your claim that it's seen as .J~1 seems incorrect.
    – Karan
    Commented May 27, 2015 at 19:10
  • @Karan ah, you're right. it changes the first name to ~1 and uses the first 3 of the extension. Tnx. Will correct it.
    – LPChip
    Commented May 27, 2015 at 19:11

Not the answer you're looking for? Browse other questions tagged .