我想用在变量中定义的扩展名对图像做一些事情。 以下脚本运行良好:
set AllowExt="jpg png bmp"
forfiles /p D:\Pictures /m *.* /c "cmd /c if not %AllowExt:jpg=% == %AllowExt% echo @file
但是下面的脚本会报错
set AllowExt="jpg png bmp"
forfiles /p D:\Pictures /m *.* /c "cmd /c if not %AllowExt:@ext=% == %AllowExt% echo @file"
错误:无效参数/选项 - 'png'。 输入“FORFILES/?”供使用。
最佳答案
你可以试试这个:
set "AllowExt=.jpg .png .bmp"
for %%a in (%AllowExt%) do (
forfiles /p D:\Pictures /m *%%a /c "cmd /c echo @file"
)
"cmd/c echo @file"
是默认命令,参见 forfiles/?
。
关于Windows 批处理脚本 - 如何过滤具有定义扩展名的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17638648/