Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

FM Variable Folder Name

Explorer ,
Feb 11, 2021 Feb 11, 2021

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

620
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 11, 2021 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, 
...
Translate
Community Expert ,
Feb 11, 2021 Feb 11, 2021

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 11, 2021 Feb 11, 2021

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 11, 2021 Feb 11, 2021

Thank you frameexpert

 

I will see your solution

 

Best Regards

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 11, 2021 Feb 11, 2021

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 11, 2021 Feb 11, 2021

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]

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 11, 2021 Feb 11, 2021

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

ONLY the folder name of my document.

Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 11, 2021 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, 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
}

 

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

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

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