1

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

For example,

dir *.1*

Will list all files whose extensions start with 1.

2
  • 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, 2012 at 14:52
  • 3
    MS-DOS supports both ? (for single character substitution) and * (for multi-character substitution).
    – M K
    Oct 19, 2012 at 15:02

2 Answers 2

2

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.

3

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 .\* |? {$_.name -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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .