2013-07-14 31 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 
相關問題