How to get album name from the folder names part

I want to create a GET Album button for update the Album Metadata.
The Album name I want to get from the Folder Names part.
The Demo Folder name is: Jurassic Park. Steven Spielberg. Advanture
Wanted Album name is : Jurassic Park

I have tried with this

@sync:dopusrt /acmd SetAttr {filepath} META album:{file|noext}

This code can update the album metadata with the file name.

I know This Regex can remove everything after first full stop

<from>([^.]+)</from>
	<to>\1</to>

But I don't have the idea how to combine it with GET Album button

You would need to use scripting it you want to apply a regular expression to the filename before using it in a command.

I am very new in scripting & tried get error & error & error

function OnClick(clickData) {
	clickData.func.command.deselect = false;
	for (var loc = new Enumerator(clickData.func.sourcetab.selected_files);!loc.atEnd();enumSelected.moveNext()) {
	var loc = window.location.pathname;
	var dir = loc.substring(0, loc.lastIndexOf('/'));
		clickData.func.command.RunCommand('SetAttr "'+loc.item()+'" META "album'"');

It would be a great help if anyone write some code about it

hi
is there anyone can help me please to find out what is wrong in my code!

Not if the only information you give is "error".

What is the error? What have you tried? Have you made any attempt to understand or debug the problem in your code yourself? Have you looked at the commands your code is generating to see if they make sense? (I showed you how to do that recently in another thread, using DOpus.Output.)

Without even reading the source code in any detail, I believe you are missing two closing curly brackets }.

I suspect you didn't copy and paste the whole code.

function OnClick(clickData)
{
		DOpus.ClearOutput();
		var cmd = clickData.func.command;
	var test = clickData.func.sourcetab.path

	DOpus.Output(test);
}

This code Return full path of the current directory
like: D:\Project Secure\Backup v.3 [02-12-2019]
But I need only the name of current directory like Backup v.3 [02-12-2019]
How can I get the current directory name in jscript?
Is there any way to use {sourcepath$|nopath|noterm} in jscript?

clickData.func.sourcetab.path returns a Path object.

Those objects have methods for getting different elements of the path, such as the folder name.

Thanks Leo for helping me. Now I can print out my current folder name in a test variable.

function OnClick(clickData)
{
		DOpus.ClearOutput();
		var cmd = clickData.func.command;
	var test = clickData.func.sourcetab.path.filepart

	DOpus.Output(test);

}


Now I want to replace all selected files META album with this test variable how to do this?

function OnClick(clickData) {
	DOpus.ClearOutput();
		var test = clickData.func.sourcetab.path.filepart
	clickData.func.command.deselect = false;
	for (var enumSelected = new Enumerator(clickData.func.sourcetab.selected_files);!enumSelected.atEnd();enumSelected.moveNext()) {
		clickData.func.command.RunCommand('SetAttr "'+enumSelected.item()+'" META "album:'+test+'"');
	}
}

This code can change album meta data with the current folder name. now I need to use regex for delete everything after the first dot . from the current folder name.
The Demo Folder name is: Jurassic Park. Steven Spielberg. Advanture
Wanted Album name is : Jurassic Park

This Regex can remove everything after first full stop in rename dialog box

<from>([^.]+)</from>
	<to>\1</to>

How to use this regex into the jscript code?

Can any one help me about this! how to use Regex with in the jscript

There are lots of examples on the forum showing how to use regex in scripts, including one you posted yourself recently.

I need to print after the last dot . string part from the current folder name.
The Demo Folder name is: Jurassic Park. Steven Spielberg. Adventure
Now I want to print : Adventure
so I have tried with substring(0, lastIndexOf(".")); Syntax. But That shows Error.

Error at line 4, position 2
Object doesn't support this property or method (0x800a01b6)

How can I print everything after the last . dot from the file name only so I want to Ignore the file extension.
my code is here:

function OnClick(clickData) {
	DOpus.ClearOutput();
		var test = clickData.func.sourcetab.path.filepart
	var splitStr = test.substring(0, test.lastindexOf("."));
	Dopus.output(splitStr);
		//for (var enumSelected = new Enumerator(clickData.func.sourcetab.selected_files);!enumSelected.atEnd();enumSelected.moveNext()) {
		//clickData.func.command.RunCommand('SetAttr "'+enumSelected.item()+'" META "album:'+splitStr+'"');
//	}
}

But That shows Error.

Error at line 4, position 2
Object doesn't support this property or method (0x800a01b6)

JScript/Javascript is case-sensitive*. Change lastindexOf to lastIndexOf and it should work:

(*For the language's own functions, methods, variables, etc. Case doesn't matter when calling ActiveScripting objects/methods like DOpus.Output which won't normally care, since for those it's the program that supplies the objects -- Opus in this example -- which interprets the name. But you need to be careful of case for anything built in to JScript.)

The is a big help for me thanks for that. But I want to print Adventure
As I see in your screen shoot It's print Jurassic Park. Steven Spielberg
The Demo Folder name is: Jurassic Park. Steven Spielberg. Adventure
But I want to print : Adventure
how to do that?

Do you understand what substring(0, lastIndexOf(".")) is doing, or have you just copied that from somewhere else?

If you understand what it's doing then it should be obvious how to make it take the last half instead of the first half.

If you don't, have a read of a guide on what substring and lastIndexOf do, and it should then become obvious.

Hi leo believe me, I am trying to Understand how It's work. Not just copy from some where.
and here is I found my solve

	var test = clickData.func.sourcetab.path.filepart
	var splitStr = test.substring(test.lastIndexOf(".")+2);
	DOpus.output(splitStr);
1 Like