How to edit metadata from filename

Greetings,
I want to make a button, to automatically set the title of my musics.
I want to use a regular expression (entered using a dialog box) to evaluate the title, and then use :
SetAttr META title:

How can I set a variable with the result of a regex, please ?

Thanks in advance for your help :slight_smile:

Now my topic becomes "How to edit metadata from filename" :slight_smile:
And I found this very useful post from AlbatorV :

So I tried to modify it, to apply for this kind of files : "1 Coming of Age.mp3"

@nodeselect
Rename FILEINFO To="{mp3track}%{mp3title}"
@script vbscript
Option Explicit
Dim DOpusRTPath
DOpusRTPath = "C:\Program Files\GPSoftware\Directory Opus\dopusrt.exe"
Dim Shell
Set Shell = CreateObject("WScript.Shell")
Function Rename_GetNewName ( strFileName, strFilePath, fIsFolder, strOldName, ByRef strNewName )
    Dim re, strCommand, track, titre, path
    Set re = new RegExp
    re.Pattern = "(.*?) (.*)(\.mp3)"
    track = re.Replace(strFileName, "$1")
    titre = re.Replace(strFileName, "$2")
    path = strFilePath & "\" & strFileName
    strCommand = """" & DOpusRTPath & """ /cmd SetAttr """ & path & """ META ""track:" & track & """ ""title:" & titre & """"
	Shell.Run strCommand,0,False
    Dopus.OutputString  "Commande : " & strCommand
    strNewName = ""
End Function

But nothing happens ! Can you help me, please ?

Pfff I'm really sorry, it works perfectly now, I just selected "Script function" instead of "standard function (opus or external)".

If someone comes here, a little more help would be welcome :slight_smile:
I would like to count the number of mp3 in the folder, and the replace the meta track from 1, to 1/10 for example.

Thank you :slight_smile:

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);
	}
}

A late answer, I'm sorry.
This code is just perfect !
Thank you very very much tbone :slight_smile:

Np, glad it works for you! o)