开发者

Windows batch filename globbing

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

echo {foo,bar,b开发者_运维问答az}/*.{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.


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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜