Filename wilcard characters in cmd.exe

  • Thread starter Thread starter Sean Nelson
  • Start date Start date
S

Sean Nelson

Guest
I'm probably a relic, but I expected the old standard "*" (match zero or more
characters) and "?" (match any 1 character) filename wildcarding characters
to work in a Command Prompt window. They do work, after a fashion, but not
in the way I would expect. For example:

dir *.d?? displays files such as "Test.docx"

dir *s.* displays files such as "exam.xls"

Interestingly, the same wildcarded search patterns work as I expect in an
Explorer search window.

What exactly are the wildcard characters that cmd.exe accepts, and how are
they interpreted?
 
Re: Filename wilcard characters in cmd.exe


"Sean Nelson" <SeanNelson@discussions.microsoft.com> wrote in message
news:42D4FD28-2BC6-42DE-8236-E0A07C9772E6@microsoft.com...
> I'm probably a relic, but I expected the old standard "*" (match zero or
> more
> characters) and "?" (match any 1 character) filename wildcarding
> characters
> to work in a Command Prompt window. They do work, after a fashion, but
> not
> in the way I would expect. For example:
>
> dir *.d?? displays files such as "Test.docx"
>
> dir *s.* displays files such as "exam.xls"
>
> Interestingly, the same wildcarded search patterns work as I expect in an
> Explorer search window.
>
> What exactly are the wildcard characters that cmd.exe accepts, and how are
> they interpreted?


You're tripping over the Short File Name (SFN) representation of your files.
When you enter the command
dir test.* /x
then you will immediately see why your own dir command worked the way it
did.
 
Re: Filename wilcard characters in cmd.exe

"Pegasus (MVP)" wrote:
> > dir *.d?? displays files such as "Test.docx"
> > dir *s.* displays files such as "exam.xls"


> You're tripping over the Short File Name (SFN) representation of your files.
> When you enter the command
> dir test.* /x
> then you will immediately see why your own dir command worked the way it
> did.


Thanks - that explains the *.d?? pattern match. Is there a way to prevent
matches against the short file names (other than turning off short filename
generation altogether)?

But it doesn't explain why "*s.???" matches "exam.xls", since this file has
no short file name.
 
Re: Filename wilcard characters in cmd.exe

See below.

"Sean Nelson" <SeanNelson@discussions.microsoft.com> wrote in message
news:EF4D6E72-21F7-436C-B7CB-8226FF147FA3@microsoft.com...
> "Pegasus (MVP)" wrote:
>> > dir *.d?? displays files such as "Test.docx"
>> > dir *s.* displays files such as "exam.xls"

>
>> You're tripping over the Short File Name (SFN) representation of your
>> files.
>> When you enter the command
>> dir test.* /x
>> then you will immediately see why your own dir command worked the way it
>> did.

>
> Thanks - that explains the *.d?? pattern match. Is there a way to prevent
> matches against the short file names (other than turning off short
> filename
> generation altogether)?

No, there isn't while SFN generation is active.

> But it doesn't explain why "*s.???" matches "exam.xls", since this file
> has
> no short file name.

You've got me there. It appears that the "*s" bit picks up the "s" in "xls"
.. . .
 
Re: Filename wilcard characters in cmd.exe

That would be the difference between ? and *. * means everything - I only
use * at the end.
"Pegasus (MVP)" <I.can@fly.com.oz> wrote in message
news:uQz0$6BIJHA.468@TK2MSFTNGP06.phx.gbl...
> See below.
>
> "Sean Nelson" <SeanNelson@discussions.microsoft.com> wrote in message
> news:EF4D6E72-21F7-436C-B7CB-8226FF147FA3@microsoft.com...
>> "Pegasus (MVP)" wrote:
>>> > dir *.d?? displays files such as "Test.docx"
>>> > dir *s.* displays files such as "exam.xls"

>>
>>> You're tripping over the Short File Name (SFN) representation of your
>>> files.
>>> When you enter the command
>>> dir test.* /x
>>> then you will immediately see why your own dir command worked the way it
>>> did.

>>
>> Thanks - that explains the *.d?? pattern match. Is there a way to
>> prevent
>> matches against the short file names (other than turning off short
>> filename
>> generation altogether)?

> No, there isn't while SFN generation is active.
>
>> But it doesn't explain why "*s.???" matches "exam.xls", since this file
>> has
>> no short file name.

> You've got me there. It appears that the "*s" bit picks up the "s" in
> "xls" . . .
>
 
Back
Top