This isn't a complete script, but will it show you what is possible. And I like to have fun playing with code.
Insert the Filename (Long) variable in a paragraph and put your text cursor in the paragraph and run this code:
#target framemaker
var doc, pgf, text, regex;
// Get the active document.
doc = app.ActiveDoc;
// Get the paragraph that contains the Filename (Long) variable.
pgf = doc.TextSelection.beg.obj;
// Get the text of the paragraph containing the text cursor.
text = getText (pgf, doc);
// Drop the filename.
text = text.replace (/\\[^\\]+$/, "");
// Drop the path except the last folder.
text = text.replace (/^.+\\/, "");
// Show me the text that will get assigned to the user variable.
alert (text);
function getText (textObj, doc) {
// Gets the text from the text object or text range.
var text = "", textItems, i;
// Get a list of the strings in the text object or text range.
if (textObj.constructor.name !== "TextRange") {
textItems = textObj.GetText(Constants.FTI_String);
} else {
textItems = doc.GetTextForRange(textObj, Constants.FTI_String);
}
// Concatenate the strings.
for (i = 0; i < textItems.len; i += 1) {
text += (textItems[i].sdata);
}
return text; // Return the text
}