Get partial characters of a filename into getstring dialong box

I'm looking to retrieve with javascript the leftmost part of a filename after the first period.

For example, if the selected file is
honda.2020.accord.txt

I'd like to have honda pre-populated in the dialog box that is called with a Getstring:

    var dlg = clickData.func.Dlg();
    var st = dlg.GetString('Collection Name:', st);

Can you point me in the right direction? I just spent time searching for this as well as trying to find the needed functionality in the manual.

Thanks.

You are looking for Javascript string manipulation. You'll find little in the Opus manual, but plenty on the web:

https://www.google.com/search?q=javascript+the+leftmost+part+of+a+filename+after+the+first+period

Would be a good example to learn a bit of regex, if that's on your bucket list :wink:

Thanks for that. I should be able to work with the string. How do I fetch the selected file name into a variable with a JavaScript?

The default script in a button (and probably 99% of all scripts in the forum) provides an example.

Ok the default script got me going. Thanks for that.

Now I'm running into a error trying parse a string:

   ***Object doesn't support this property or method (0x800a01b6)***

I found this four year Old Forum Post that outlines this. I'm wondering if indexof still isn't naively supported?

Trying to find the first "." in the string:

	var testme = "hello.22.22";
	DOpus.Output(testme.indexof(".",1));

Microsoft haven't updated JScript in a long time, and probably never will as they've abandoned it (despite not replacing it with anything, sigh), so the old information still applies to JScript today.

1 Like

I found this four year Old Forum Post

You went a bit too far - going back two days would have been enough.

Can you spot the difference?

Oh geez. Thank you LXP!

I MUST get better at this.

String(item.realpath).indexOf(st)