批处理文件:列出所有不以“SP”开头的文件
我有一个 DOS 批处理文件,它对以文本“SP”开头的文件执行操作,如下所示:
FOR /F "tokens=*" %%A IN ( 'DIR SP*.sql /s /b' ) DO ECHO .compile_file = "%%A" >> output.txt
这里的关键位显然是:
DIR SP*.sql /s /b
我需要在上面的“FOR”行之前执行类似的操作,但对于所有其他文件则不需要从 SP*.sql 开始
类似:
FOR /F "tokens=*" %%A IN ( 'DIR [^SP]*.sql /s /b' ) DO ECHO .run_file = "%%A" >> output.txt
FOR /F "tokens=*" %%A IN ( 'DIR SP*.sql /s /b' ) DO ECHO .compile_file = "%%A" >> output.txt
有谁知道我该怎么做? 我可以使用正则表达式来做这种事情吗?
该批处理文件将在 Windows XP 中的 CMD 下运行。
干杯
I have a DOS batch file that performs an action for files beginning with text "SP", as follows:
FOR /F "tokens=*" %%A IN ( 'DIR SP*.sql /s /b' ) DO ECHO .compile_file = "%%A" >> output.txt
The key bit here is obviously:
DIR SP*.sql /s /b
I need to do a similar thing before the "FOR" line above, but for all other files not starting with SP*.sql
Something like:
FOR /F "tokens=*" %%A IN ( 'DIR [^SP]*.sql /s /b' ) DO ECHO .run_file = "%%A" >> output.txt
FOR /F "tokens=*" %%A IN ( 'DIR SP*.sql /s /b' ) DO ECHO .compile_file = "%%A" >> output.txt
Does anyone know how I can do this?
Can I use regex for this sort of thing?
The batch file will run under CMD in Windows XP.
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在批处理中,通常您可以使用
findstr
和/V
来否定 regex ,例如尝试将文件名传递给
findstr
并查看效果如何In batch, usually you can use
findstr
with/V
to negate regex , egtry passing the filename to
findstr
and see how it goes