Dir with wildcard returning unexpected result

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
varianjv
Posts: 4
Joined: 02 May 2019 15:19

Dir with wildcard returning unexpected result

#1 Post by varianjv » 02 May 2019 15:23

Hi there,
I have a lot of files in a folder

I run the following to get a subset

dir /b pa1*.txt

I would expect this to bring back only files like

pa1.txt
pa11.txt etc

However it also brings back files like
pay1.txt

Any reason for this does any one know

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Dir with wildcard returning unexpected result

#2 Post by Squashman » 02 May 2019 15:49

It is matching the short file names. 8.3.
Run the DIR command from a command prompt and use the /X option to see what I mean.

varianjv
Posts: 4
Joined: 02 May 2019 15:19

Re: Dir with wildcard returning unexpected result

#3 Post by varianjv » 03 May 2019 04:52

I'm not using the short name format.
I tried with the /X and i still get filenames I dont want

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Dir with wildcard returning unexpected result

#4 Post by Squashman » 03 May 2019 08:22

varianjv wrote:
03 May 2019 04:52
I'm not using the short name format.
I tried with the /X and i still get filenames I dont want
Never said you were using short file names nor did I say using /X would solve your problem. I am saying the default behavior is that the WILDCARD will also match short file names.

The EXAMPLE your provided does not output what you say it does because the file names you provided are already in 8.3 format. Don't ever post an example without testing it first.

Go back to the directory that you are having problems with. When you run the DIR command with the /X option you should see that the short file names are matching your search mask.

varianjv
Posts: 4
Joined: 02 May 2019 15:19

Re: Dir with wildcard returning unexpected result

#5 Post by varianjv » 07 May 2019 14:42

Sorry
I understand what you mean now.
Can I exclude these?

Post Reply