试一下BAT_JS混编呢- @set @x=0 /* @echo off&cscript -nologo -e:jscript %0 "D:\mp3" "E:\data" & pause & exit */
- var pad = function (n) { return ('0'+Math.floor(n)).slice(-2)}
- var fso=new ActiveXObject("Scripting.FileSystemObject");
- var WMP = new ActiveXObject("WMPlayer.OCX");
- var i = 0, mediaFiles = [];
-
- var Folder=fso.GetFolder(WScript.Arguments.Item(0));
- for(var e=new Enumerator(Folder.Files);!e.atEnd();e.moveNext()){
- var f=e.item();
- var ext = f.Name.split('.').pop().toLowerCase();
- if (ext === 'mp3') {
- mediaFiles[i++] = {file: f, duration: Math.floor(WMP.newMedia(f).GetItemInfo("Duration"))};
- }
- }
-
- mediaFiles.sort(function(a, b) { return a.duration - b.duration});
-
- function binarySearch(mediaFiles, t) {
- var left = 0, right = mediaFiles.length - 1;
- while (left < right) {
- var mid = Math.floor((left + right) >> 1);
- if (mediaFiles[mid].duration > t) {
- right = mid;
- } else {
- left = mid + 1;
- }
- }
- return (left < mediaFiles.length) ? left : null;
- }
-
- var Folder=fso.GetFolder(WScript.Arguments.Item(1));
- for(var e=new Enumerator(Folder.SubFolders);!e.atEnd();e.moveNext()){
- var subFolder=e.item();
- for(var f=new Enumerator(subFolder.Files);!f.atEnd();f.moveNext()){
- var file=f.item();
- var ext = file.Name.split('.').pop().toLowerCase();
- if (ext === 'wav') {
- var t = WMP.newMedia(file).GetItemInfo("Duration");
- var FileIndex = binarySearch(mediaFiles, t);
- if (FileIndex !== null) {
- var ToFile = mediaFiles[FileIndex];
- fso.CopyFile(ToFile.file, subFolder+'\\');
- mediaFiles.splice(FileIndex, 1);
- }
- }
- }
- }
复制代码
|