Extract the filename stem only of the first of one or more selected files

Objective
I want to grab the stem of the filename of the first file of I one or more files currently selected.

Default Script
I have butchered the default JS script as per below.
I run the script and get the output also shown below

Question01
How might I best get what I am after? I am getting the file and path currently. I only want the stem of the filename as highlighted with green in the output.

Many thanks as always

image

function OnClick(clickData)
{
    // Selected files enumerator from the default JScript app
    // --------------------------------------------------------
    DOpus.ClearOutput();
    // --------------------------------------------------------
    var cmd = clickData.func.command;
    cmd.deselect = false; // Prevent automatic deselection
    // --------------------------------------------------------
    cmd.RunCommand("Set VIEW=Details");
    // --------------------------------------------------------
    DOpus.Output("Selected items in " + clickData.func.sourcetab.path + ":");
    if (clickData.func.sourcetab.selected.count == 0)
    {
        DOpus.Output("  (none)");
    }
    else
    {
        var eSel = new Enumerator(clickData.func.sourcetab.selected);
        if (eSel.item().is_dir)
        {
            DOpus.Output("  (d) " + eSel.item().RealPath);
        }
        else
        {
            DOpus.Output("  (f) RealPath :" + eSel.item().RealPath);
            DOpus.Output("  (h) item     :" + eSel.item());
            DOpus.Output("  (i) stem     :" + eSel.item().stem);
        }
    }
    // --------------------------------------------------------
    // --------------------------------------------------------
    // --------------------------------------------------------
}
name_stem string Returns the filename "stem" of the item. This is the name of the item with the filename extension removed. It will be the same as the name for folders.
name_stem_m string Returns the filename "stem" of the item, taking multi-part extensions into account. For example, a file called "file.part1.rar" might return "file.part1" for name_stem but "file" for name_stem_m.

https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Scripting/Item.htm

1 Like

Eureka!
Thanks @Ixp - not for the first time.
would it be true then that....
eSel = Collection of items being enumerated
eSel.item = Property representing the current item?
Now clear to me that eSel.item is in fact an Item object.
Confused....thanks again....

clickData.func.sourcetab.selected is an Opus collection

eSel is a JScript Enumerator Object

item() is a JScript method that returns the current element from the Enumerator Object

eSel.item() is an Opus item object (because you are enumerating a collection of item objects in this example)

1 Like