Is there any wildcard for a digit in the command-prompt?
For example,
dir *.1*
Will list all files whose extensions start with 1.
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.
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
for /r
.
?
as a wildcard character, not*
. Perhaps you mean the Windows Command Prompt (cmd.exe) instead?