cmd has wildcard bug?

3

0

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?

Živka Blažević

Posted 2015-05-27T18:55:14.460

Reputation: 31

Question was closed 2015-09-23T17:56:00.207

3One 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 – 2015-05-27T19:06:19.850

@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 – 2015-05-28T03:51:39.523

@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 – 2015-05-28T03:57:39.283

Answers

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.

boot13

Posted 2015-05-27T18:55:14.460

Reputation: 5 551

1This seems to be the correct reason, which can be confirmed by using what snoopy wrote. – Karan – 2015-05-27T19:18:36.337

1I'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 – 2015-05-27T21:37:17.223

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.)

Konrad

Posted 2015-05-27T18:55:14.460

Reputation: 31

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

Posted 2015-05-27T18:55:14.460

Reputation: 42 190

dir /x shows .JPEG as .JPE, so your claim that it's seen as .J~1 seems incorrect. – Karan – 2015-05-27T19:10:11.193

@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 – 2015-05-27T19:11:25.980