通过JS获取时长,传递给批处理处理。
@set @n=0; /* & echo off
cd d:\test
for /f "tokens=1,2 delims==" %%a in ('dir /b/s *.mp3^|cscript -nologo -e:jscript "%~0"') do (
set "f=%%b"
set /a h=%%a/3600+100,m=%%a%%3600/60+100,s=%%a%%60+100
setlocal enabledelayedexpansion
echo !f! !h:~1!:!m:~1!:!s:~1!
endlocal
)
pause & exit/b & rem */
//jscript代码
WMP = new ActiveXObject("WMPlayer.OCX");
while(!WScript.StdIn.AtEndOfStream) {
f = WScript.StdIn.ReadLine();
t = WMP.newMedia(f).getItemInfo("Duration");
t = parseInt(t)
WScript.Echo(t + "=" + f)
}
将获取到的秒数取整后传递给批处理处理。后来发现大神apang的方法更好。
apang的代码
WMPlayer.OCX
@set @n=0; /* & echo off
dir /a-d /b /s *.mp3 | cscript -nologo -e:jscript "%~0"
pause & exit/b & rem */
//jscript代码
WMP = new ActiveXObject("WMPlayer.OCX");
while(!WScript.StdIn.AtEndOfStream) {
f = WScript.StdIn.ReadLine();
t = WMP.newMedia(f).getItemInfo("Duration");
hh = Math.floor(t/3600)+100;
mm = Math.floor(t%3600/60)+100;
ss = Math.floor(t%60)+100;
t = (hh + ":" + mm + ":" + ss).replace(/\d(\d\d)/g, "$1");
WScript.Echo(t)
}
Shell.Application
@set @n=0;/* & echo off
dir /a-d /b /s *.mp3 | cscript -nologo -e:jscript "%~0" > List.txt
pause & exit/b & rem */
//jscript代码
objShell = new ActiveXObject("Shell.Application");
while(!WScript.StdIn.AtEndOfStream) {
f = WScript.StdIn.ReadLine();
objFolder = objShell.NameSpace(f.replace(/^(.+)\\.+$/, "$1"));
objItem = objFolder.ParseName(f.replace(/^.+\\(.+)$/, "$1"));
t = objFolder.GetDetailsOf(objItem, 27);
WScript.Echo(f + " " + t);
}
第三方处理
@echo off
setlocal enabledelayedexpansion
cd z:\
(for /f "delims=" %%i in ('dir /b *.mp3') do (
for /f "tokens=3 delims=," %%j in ('tag.exe "%%i" 2^>^&1 ^| findstr "playtime"') do (
set pt=%%j
set pt=!pt: playtime =!
echo %%i^=!pt!
)
))>tag.txt
关于2^>^&1 ^|
的说明:
Bathome老大Batcher的回复:
大部分命令执行的结果可以直接通过管道传递给后面的命令进行后续操作:
xxx | findstr "playtime"tag比较特殊,它的输出在2号句柄,所以需要重定向到1号句柄,然后再通过管道传递:
tag.exe "%%i" 2>&1 | findstr "playtime"for命令里面需要对特殊字符进行转移,所以就变成了:
tag.exe "%%i" 2>&1 ^| findstr "playtime"
- 百度网盘
- 提取码:
mh5q
网友评论