2013-07-14 66 views
1

我想对图像中的某些东西在扩展名中定义变量。 下面的脚本运行良好:Windows批处理脚本 - 如何使用定义的扩展名筛选文件

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" 

ERROR:无效的参数/选项 - 'PNG'。 输入“FORFILES /?”供使用。

回答

4

你可以试试这个:

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

+1

修正如下,它运行良好。 组AllowExt = .JPG .PNG .BMP 用于%%一个在(%AllowExt%)做( FORFILES/P d:\图片/米* %%的A/C “CMD/C回波@file” ) –

+0

@JinHo你说得对,应该没有双引号:) – Endoro

0

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

@echo off 
set "AllowExt=jpg png bmp" 
set "AllowExt= %AllowExt%" 
set "AllowExt=%AllowExt: = *.%" 
    pushd "D:\Pictures" 
    for %%a in (%AllowExt%) do (
    echo "%%a" 
    ) 
    popd 
相关问题