FM Variable Folder Name

Explorer ,
Feb 11, 2021

Copy link to clipboard

Copied

Hi. I have a little problem with a variable.
i would like to recuperate the folder name, of my document, as value, to put it, on a master page.
I tought it was a system variable <$dir>.... but it don't exist.
Is it possible to create a user variable to get the content of the folder name?
Thank You.

JC

Views

102

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

1 Correct Answer

Adobe Community Professional , Feb 11, 2021
frameexpert Adobe Community Professional , Feb 11, 2021
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, ...

Likes

Translate

Translate
Jump to answer Jump to answer
Adobe Community Professional ,
Feb 11, 2021

Copy link to clipboard

Copied

Hi,

 

I think that there is only the system variable Filename (long) which you can use.

It contains the building block <$fullfilename>.

That's the path plus file name.

Does this help?

Otherwise you would need to write an ExtendScript script.

This should not be too difficult.

 

Best regards

 

Winfried

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Feb 11, 2021

Copy link to clipboard

Copied

Here is the process I would use to do it with a script.

1) Find the document's Right master page. Every document has one.

2) Create a temporary text frame on the master page.

3) Insert the Filename (Long) variable in the text frame's first paragraph.

4) Retrieve the full filename value from the text frame.

5) Parse the value to remove the filename and leave the folder.

6) Make or update the user variable that should contain this value.

I am busy right now and can't do this for free, but if you want a quote for a script like this, please contact me offlist. A script like this could be triggered automatically so once it is written, you wouldn't have to think about it.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
JCmayer AUTHOR
Explorer ,
Feb 11, 2021

Copy link to clipboard

Copied

Thank you frameexpert

 

I will see your solution

 

Best Regards

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
JCmayer AUTHOR
Explorer ,
Feb 11, 2021

Copy link to clipboard

Copied

Thank you Winfried,

but I don't need all the path, only the folder name, in which there is the document.

And I cannot write an ExtendScript, because, the document is an End User Template.

Best regards

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Feb 11, 2021

Copy link to clipboard

Copied

I think the variable you want is <$fullfilename>.

 

All system variables are listed in the Variable panel. 

 

[Ninja'd: this is what happens when you get distracted by work]

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
JCmayer AUTHOR
Explorer ,
Feb 11, 2021

Copy link to clipboard

Copied

Sorry LinSims, but I don't want all the path...

ONLY the folder name of my document.

Thanks

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Feb 11, 2021

Copy link to clipboard

Copied

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
}

 

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
JCmayer AUTHOR LATEST
Explorer ,
Feb 11, 2021

Copy link to clipboard

Copied

Hi frameexpert,

It works well on the "masterPage" !!

I just have to retrieve the result, and put it in another variable .. but I have to learn ExtendScript 🙂
thank you so much

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more