//-----------------------------------------------------------------------------
//  lib constants & functions
//-----------------------------------------------------------------------------

var FSO = WScript.createObject("Scripting.FileSystemObject");

// Makes iteration sweeter
Enumerator.prototype.getAndMove = function(){
    var i=this.item();this.moveNext();return i;
}

// Irritating that native function doesn't return file if found.
function fileExists(path){
    return FSO.FileExists(path)? FSO.getFile(path):null;
}
//-----------------------------------------------------------------------------
//  main script
//-----------------------------------------------------------------------------

var args = WScript.arguments
// Stop if no arguments sent
if(!args.length) { WScript.Echo('The script requires arguments'); WScript.Quit(); }

var parensReg = /^(.*)\[[0-9]*\](\.[^\.]*)$/;
var parensRep = '$1$2';
var paths = new Enumerator(args);
var path, file;

while( path = paths.getAndMove() )
{
    if( parensReg.test(path) && ( file = fileExists(path) ) )
        file.move( path.replace(parensReg, parensRep) );
}


