• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

Javascript 根据文件的跟踪编号重命名目录下的音乐文件

JavaScript 水墨上仙 2283次浏览

Javascript 根据文件的跟踪编号重命名目录下的音乐文件

Array.prototype.add = function ( item ) {
    this [ this.length ] = item;
}
Array.prototype.iterate = function ( callback ) {
    for ( var i = 0; i < this.length; i++ ) {
        callback ( this [ i ] );
    }
}
DirectoryUtility = {
    _fso : WScript.CreateObject ( "Scripting.FileSystemObject" ),
    // function getCurrentDirectory: returns currentDirectory path 
    // with a trailing backslash.
	getCurrentDirectory : function ( ) {
		var scriptFullName = WScript.ScriptFullName;
        var scriptName = WScript.ScriptName;
        return scriptFullName.substr ( 0, scriptFullName.lastIndexOf ( scriptName ) );
	},
	
	getFiles : function ( path, re ) {
	    var folder = this._fso.GetFolder ( path );
	    var files = folder.Files;
	    
	    var filteredFiles = new Array ( );
	    
	    for ( var e = new Enumerator ( files ); ! e.atEnd ( ); e.moveNext () ) {
	        var file = e.item ( );
	        if ( re.test ( file.Name ) ) {
	            filteredFiles.add ( file );
	        }
	    }
	    return filteredFiles;
	}
}
var du = DirectoryUtility;
var path = du.getCurrentDirectory ( );
var args = WScript.Arguments;
var pattern;
if ( args.Length > 0 ) {
	pattern = "\\." + args ( 0 ) + "$";
} else {
	WScript.Quit ( );
}
var re = new RegExp ( pattern );
var files = du.getFiles ( path, re );
var printName = function ( fileName ) {
    WScript.Echo ( fileName );
}
var rename = function ( file ) {
    WScript.Echo ( "Specify a track number for \""
        + file.Name + "\": " );
    var line = WScript.StdIn.ReadLine ( );
    var track = new Number ( line );
    if ( track < 10 ) {
        newName = "0" + track;
    } else {
        newName = track.toString ( );
    }
    newName += " " + file.Name;
    file.Name = newName;
}
files.iterate ( rename );
/* 用法 */
cscript .js extension


开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明Javascript 根据文件的跟踪编号重命名目录下的音乐文件
喜欢 (0)
加载中……