5

Is something like this possible in the Windows standard shell using wildcards only?

$ ls -1 003[5,8]0
00350
00380
lukuluku
  • 4,344
  • 3
  • 30
  • 35

2 Answers2

5

Not in the standard windows command shell (cmd.exe). It understands only the ? and * wildcards; no regular expressions.

Do you have the option of installing Cygwin, Windows Powershell, or another enhanced shell?

Simbilis
  • 66
  • 2
  • Unfortunately im not able to install any other shells, since this is a production environment and i dont have rights to do so – lukuluku Jul 19 '12 at 09:12
  • I don't think thats strictly true. You could do a regex with `findstr` with the input from a piped `dir` command, I'm not sure how to write it, but I think it should be possible. I'm sure @dbenham or @jeb will be able to come up with something :) – Bali C Jul 19 '12 at 10:16
  • Fair enough. If you just want the text output and not any side effects from the command, then `dir | findstr /r "003[5,8]0"` will work. – Simbilis Jul 19 '12 at 10:21
  • 1
    I will accept this answer, because there is no native way in windows... only by using other commands, which is not an option in my case – lukuluku Jul 19 '12 at 10:41
  • I tried this hack of @Simbilis but there was no result in the cmd.exe output nor anything new in my working directory. – panny Feb 10 '13 at 17:02
2

yes, you can. Not with a single command, but with a combination of FOR and IF. Try this to get you started...

setlocal enabledelayedexpansion
for %%a in (003?0) do (
  set fn=%%a
  set fnl=!fn:~3,1!
  if .!fnl!==.5 (
    echo !fn!
  )
  if .!fnl!==.8 (
    echo !fn!
  )
)
PA.
  • 28,486
  • 9
  • 71
  • 95