2

In short, I would like to port this bash expression to a windows batch file:

echo {foo,bar,baz}/*.{agent,event,plan}

Currently I use echo foo/*.agent foo/*.event foo/*.plan bar/*.agent etc... but as the number of directories grow and some new extensions are used it gets very tiresome to modify this line.

ext
  • 2,593
  • 4
  • 32
  • 45

1 Answers1

0

One per line (Not sure if that is ok):

@echo off
for %%A in (foo,bar,baz) do (
 for %%B in (agent,event,plan) do echo %%A/*.%%B
)

For all in one line, you probably need a hack:

@echo off
SETLOCAL ENABLEEXTENSIONS
for %%A in (foo,bar,baz) do (
 for %%B in (agent,event,plan) do (SET /P "dummy=%%A/*.%%B ") < NUL
)
echo.

Treat as a list of files and folders (will only print existing files):

@echo off
SETLOCAL ENABLEEXTENSIONS
for %%A in (foo,bar,baz) do (
    for %%B in (agent,event,plan) do (
        for %%C in (%%A/*.%%B) do (SET /P "dummy=%%A/%%~nxC ") < NUL
    )
)
echo.
Anders
  • 97,548
  • 12
  • 110
  • 164
  • Sorry, need all the arguments on a single line. – ext Nov 25 '10 at 20:52
  • @ext Sadly there is no real array/list support in windows echo. Is there no way for you to accept per line input? Anything else is going to be a hack... – Anders Nov 25 '10 at 20:56
  • @Anders Sadly no, arguments are being feed to a (proprietary) parser which must know about all files to resolve dependencies. But I guess the hack is ok, better than manually changing the line each time which is time-consuming and error-prone. – ext Nov 25 '10 at 20:59
  • 3
    Well, there is the small problem that the * wildcard isn't expanding. – ext Nov 25 '10 at 21:09
  • Ohh, I stand corrected, I assumed the "shell" would expand no matter what the command was and thus replaced the real command (invoking java with quite a lot of arguments) with echo. – ext Nov 25 '10 at 21:26
  • cmd.exe does not expand * or ?, windows does not work like that. – Anders Nov 25 '10 at 21:31
  • 1
    On a unrelated note, does anyone know how to force a specific format for a stackoverflow code block? – Anders Nov 25 '10 at 21:34
  • @Anders Do you mean like https://meta.stackexchange.com/a/184109/130885 ? It doesn't support batch files – endolith Jul 12 '17 at 15:27