How to edit metadata from filename

I overhauled the code a bit as it made use of the outdated rename-script hack, while also using the external dopusrt.exe to run required actions. The latter isn't the suggested way either, so here you get something v11 complaint. o)

This reads the track from the filename and sets the track-meta to "/".
Be aware that your files need to have track information that matches the regexp, track numbers must also be less/equal than the total number of files selected. So this won't work on a filename containing track index 9 and only 6 files selected. The SetAttr command seems to validate the input, what a clever beast! o)

@script jscript

function OnClick(data){
	var files = data.func.sourcetab.selected_files;
	var cmd = data.func.command; cmd.ClearFiles();
	var re = new RegExp("(.*?) (.*)(\\.mp3)");
	for(var i=0;i<files.count;i++){
		DOpus.Output("File: [" + files(i).name+"]");
		var matches = String(files(i).name).match(re);
		if (!matches){ DOpus.Output("    skipped"); continue; }
		var track = matches[1]; //var title = matches[2];
		var cmdli = 'SetAttr META="track:'+track+'/'+files.count+'" FILE="'+files(i).realpath+'"';
		DOpus.Output("    cmd: " + cmdli);
		cmd.RunCommand(cmdli);
	}
}