支持多级文件夹- @echo off
- setlocal ENABLEDELAYEDEXPANSION
- chcp 936
-
- set ffPath=D:\Program Files
-
- set folderPath=%~dp1
- set folderName=%~nx1
-
- pushd "%folderPath%"
-
- call :C_get-Duration "%folderName%" time
-
- popd
-
- pause
- exit/b
-
- Usage: %0 <folder> <return:duration>
- :C_get-Duration
- setlocal
-
- set folderName=%~1
- pushd "%folderName%"
- set/a level+=1
-
- echo,
- echo ---- %level% %CD% ----
-
- set timeSubfolderAll=0
- for /f "usebackq tokens=* delims=" %%a in (` 2^>nul dir /b /ad . `) do (
- echo "%%a"
- if not "%%a" == "" (
- call :C_get-Duration "%%a" timeSubfolder
- set/a timeSubfolderAll+=!timeSubfolder!
- )
- )
-
- echo "--1--"
- set time=0
- for /f "usebackq tokens=* delims=" %%a in (` 2^>nul dir /b *.mp4 `) do (
- for /f "usebackq" %%i in (`" "%ffpath%\ffprobe.exe" -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "%%a" "`) do (
- set time=!time! + %%i
- )
- )
- for /f "usebackq" %%a in (` powershell -command " [math]::Ceiling( (%time%) / 60 ) " `) do (
- set time=%%a
- )
- echo %time%
-
- echo "--2--"
- set/a time=0
- for /f "usebackq tokens=* delims=" %%a in (` 2^>nul dir /b *.mp4 `) do (
- for /f "usebackq tokens=1,2 delims=." %%i in (`" "%ffpath%\ffprobe.exe" -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "%%a" "`) do (
- set/a time+=%%i
- )
- )
- set/a time/=60
- set/a q=%time%%60
- if %q% gtr 0 (set/a time+=1)
- echo %time%
-
- echo "--3--"
- set/a time=0
- for /f "usebackq tokens=* delims=" %%a in (` 2^>nul dir /b *.mp4 `) do (
- for /f "usebackq tokens=2,3,4 delims=:. " %%i in (` ""%ffpath%\ffprobe.exe" "%%a" 2>&1 | findstr Duration" `) do (
- set/a time+=1%%i*3600+1%%j*60+1%%k-100*3600-100*60-100
- )
- )
- set/a time/=60
- set/a q=%time%%60
- if %q% gtr 0 (set/a time+=1)
- echo %time%
- set/a time+=%timeSubfolderAll%
-
- popd
- set/a level-=1
- echo,
- echo ---- %level% %CD% ----
- echo ren "%folderName%" "%folderName%[%time%]"
- echo,
- (
- endlocal
- set %2=%time%
- )
-
- goto :eof
复制代码
|