2

我想对具有在变量中定义的扩展名的图像做一些事情。以下脚本运行良好:

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 /?” 供使用。

4

2 回答 2

5

你可以试试这个:

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 /?.

于 2013-07-14T10:47:06.563 回答
1

这应该为您提供所需的文件名。

@echo off
set "AllowExt=jpg png bmp"
set "AllowExt= %AllowExt%"
set "AllowExt=%AllowExt: = *.%"
  pushd "D:\Pictures"
   for %%a in (%AllowExt%) do (
     echo "%%a"
   )
  popd
于 2013-07-14T12:34:23.823 回答