Unexpected behavior with DIR command in Windows 10 command window

David D 21 Reputation points
2022-10-16T05:45:28.323+00:00

I have run into some unexpected behavior with the Windows 10 DIR command. Specifically, if I include a numeral between wildcards when doing a directory search I get unexpected results.

For example, with the following files in a directory:

 Directory of G:\TEST  
  
10/15/2022  22:26               314 1.txt  
10/15/2022  22:26               357 2.txt  
10/15/2022  22:27               535 a b c.txt  
10/15/2022  22:27               488 a b.txt  
10/15/2022  22:26               400 a.txt  
10/15/2022  22:28               731 abc def ghi.txt  
10/15/2022  22:27               629 abc def.txt  
10/15/2022  22:27               580 abc.txt  
10/15/2022  22:27               678 abcdefg.txt  
10/15/2022  22:30               789 abcdefghijklmnop.txt  
10/15/2022  22:26               443 b.txt  

if I type the command: DIR *1* I would expect to get a single listing back - 1.txt

But instead I get this:

DIR *1*  

10/15/2022  22:26               314 1.txt  
10/15/2022  22:27               488 a b.txt  
10/15/2022  22:27               629 abc def.txt  
10/15/2022  22:27               535 a b c.txt  

Similarly,

DIR *2*  

10/15/2022  22:26               357 2.txt  
10/15/2022  22:28               731 abc def ghi.txt  

DIR *3*  

10/15/2022  22:30               789 abcdefghijklmnop.txt  

DIR *4*  

File Not Found  

DIR *5*  

10/15/2022  22:27               488 a b.txt  

and so on. I am not sure what this result is telling me. I have searched around on the web for documentation about some hidden feature in the DIR command that treats numerals between wildcards as some sort of special search parameter, but haven't found anything.

Does anyone know what is happening here?

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,723 questions
0 comments No comments
{count} votes

Accepted answer
  1. Gary Nebbett 6,086 Reputation points
    2022-10-16T07:10:29.673+00:00

    Hello David,

    Try adding a "/x" option to the "dir" commands to display the "short names" of the files. You will probably then see what is causing the unexpected matches.

    Gary

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.