Windows 批处理文件名通配

发布于 2024-10-04 06:49:10 字数 224 浏览 0 评论 0原文

简而言之,我想将此 bash 表达式移植到 Windows 批处理文件中:

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

目前我使用 echo foo /*.agent foo/*.event foo/*.plan bar/*.agent 等... 但随着目录数量的增长和一些新扩展的使用,修改这一行变得非常烦人。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

节枝 2024-10-11 06:49:10

每行一个(不确定是否可以):

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

对于一行中的所有内容,您可能需要一种技巧:

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

将其视为文件和文件夹列表(仅打印现有文件):

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

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文