批处理文件,删除长度超过3秒的所有.wavs

时间:2017-03-03 03:52:56

标签: windows batch-file audio

我正在创建一个.bat来删除目录中所有.wav的长度超过3秒,我发现this question that can be used to delete all .mp3's / .wav's under 3 seconds using MediaInfo,你如何更改它以删除大于3秒的文件。不到3秒?您必须删除'echo'才能执行

  @echo off
set "exe=MediaInfo.exe"
for /r %%a in (*.wav) do (
"%exe%" -f "%%a" | find "Duration" | findstr /r "00:00:0[210]" >nul && echo del "%%a"
)
pause

使用单个文件运行媒体信息输出:

Duration                                 : 203
Duration                                 : 203ms
Duration                                 : 203ms
Duration                                 : 203ms
Duration                                 : 00:00:00.203
Duration                                 : 00:00:00.203
Duration                                 : 203
Duration                                 : 203ms
Duration                                 : 203ms
Duration                                 : 203ms
Duration                                 : 00:00:00.203
Duration                                 : 00:00:00.203
Press any key to continue . . .

Theese是00:00:0 [210]下的文件,但我想针对的是00:00:0 [210]

1 个答案:

答案 0 :(得分:2)

此代码未考虑毫秒数,并假设最后一段持续时间输出将采用此格式00:00:00.123

@echo off

for /r %%F in (*.wav) do (
    FOR /F "tokens=2,3,4 delims=:. " %%G IN ('mediainfo.exe -f "%%F" ^| find "Duration"') DO (
        set "ftime=%%G%%H%%I"
    )
    setlocal enabledelayedexpansion
    IF "!ftime!" GTR "000003" DEL "%%F"
    endlocal
)
pause