Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any wildcard for a digit in the command-prompt?

For example,

dir *.1*

Will list all files whose extensions start with 1.

share|improve this question
Are you sure you mean MS-DOS? Because as far as I know, MS-DOS used ? as a wildcard character, not *. Perhaps you mean the Windows Command Prompt (cmd.exe) instead? – Indrek Oct 19 '12 at 14:52
MS-DOS supports both ? (for single character substitution) and * (for multi-character substitution). – M K Oct 19 '12 at 15:02
up vote 1 down vote accepted

No, MS-DOS supports only two wildcard characters (based on CP/M). They're "*", indicating any sequence of characters, and "?", indicating a single character. There is no distinction of alphabets and numerals in the wildcards and there is no support for regular expressions to constrain the wildcard to digits.

share|improve this answer

The answer to your literal question is 'no' - but if your real question is:

Can I somehow select only files containing a digit in their name under cmd?

then if it's anything nt based (more specifically W2k plus) yes it can be done. The trick is to use findstr, which supports simple regexes, to filter out the results.
dir /b |findstr /r "\.[0-9]" will give you results similar to what dir in your example would. This means it will also return file.1st.second (as dir would).
Small issue here is it will only list file names, but even that can be resolved:
for /f %F in ('dir /b ^|findstr /r "\.[0-9]"') do @echo %~ftzaF will print your listing nicely formatted dir style. Note it has to be run in current directory!

OR (what I would recommend)
if you have powershell available (or you're willing to install it) fire it up and exec:
gi .\* |? {$ -match "\.[0-9]"}

Edited as per OP comment:

This will enumerate files using for /r:
Simplest, but very slow (practically unusable for anything but few files), as it runs findstr for every line:

for /r "c:\temp" %F in (*) do @echo %~nxF | findstr /r "\.[0-9]" && echo %F

More complex, but fast (uses specially prepared strings to allow piping to single instance of findstr:

for /f "tokens=2 delims=* eol=*" %F in ('^(for /r "directory_root" %F in ^(*^) do @echo %~nxF*%~dpnxF^) ^|findstr /r "\.[0-9].*\*"') do @echo %F 

or (functionally the same, but easier to read :>)

(for /r "directory_root" %F in (*) do @echo %~nxF*%~dpnxF) | for /f "tokens=2 delims=* eol=*" %F in ('findstr /r "\.[0-9].*\*"') do @echo %F

All examples as run directly from command line

share|improve this answer
well, I'm not using dir specifically. Actually need to loop over files dos batch files using the for /r. – Archival Oct 19 '12 at 21:40
@Archival Still applicable, see my edit. – wmz Oct 20 '12 at 13:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.