如果子文件夹包含批处理文件中的视频文件,则运行命令

时间:2016-09-28 16:06:03

标签: batch-file

如果startfolder的子文件夹或子文件夹包含以下视频文件类型,我想执行命令.mp4 .mov .wmv .avi

即。可以使用多个通配符吗?

@echo off
SETLOCAL enableDelayedExpansion
color 0B

SET STARTFOLDER=C:\Users\%Username%\LocalData\Video Files

for /d %%d in ("%STARTFOLDER%\*") do (
for %%f in ("%%d") do (
If exist "%%f\*.mp4 *.mov *.wmv *.avi" (
    Echo subfolder or subfolder of subfolder contains a video file
    Echo  ***This bit not working***
)
)

2 个答案:

答案 0 :(得分:1)

假设您只想检查子文件夹而不是子子文件夹,这是一种简单的方法。

@echo off & setlocal enabledelayedexpansion

SET STARTFOLDER=C:\Users\%Username%\LocalData\Video Files

for /d %%d in ("%STARTFOLDER%\*") do (
    pushd "%%~d"
    dir /b *.mp4 *.mov *.wmv *.avi 1>nul 2>nul
    if !errorlevel!==0 echo "%%~d"
    popd
)

答案 1 :(得分:0)

也许这就是你追求的目标?

@Echo Off
SetLocal EnableDelayedExpansion
Color 0B
Set "StartFolder=%UserProfile%\LocalData\Video Files"
Set i=0
For /R "%StartFolder%" %%A In (*.mp4 *.mov *.wmv *.avi) Do (
    2>Nul Set InFld[|Find "]=%%~dpA">Nul 2>&1||(Set/A i+=1
        Set "InFld[!i!]=%%~dpA"))
If %i% Equ 0 (Echo No video files within the tree: %StartFolder%
    GoTo :EndIt)
Echo= The following folders within %StartFolder% contain a video file:
For /L %%I In (1,1,%i%) Do Echo= !InFld[%%I]:%StartFolder%=!
:EndIt
Echo=
Pause
Exit/B