Skip to main content
cakeytaste
Participating Frequently
March 23, 2017
Answered

Pulling file location into textfield

  • March 23, 2017
  • 2 replies
  • 680 views

Hello folks.

I'm attempting to pull the file folder in which my PDF is contained into a text field. I'm assuming there is a way to do this in the document javascripts, but I cannot seem to figure it out.

Is there way to either:

1) determine the folder name in which the PDF is located and push that into a text field (e.g., the fold name is "412" and that's what I'd like in the text field), or

2) Remove a portion of the file name itself, and push what's remaining into a text field (e.g., the file name is "Review Documentation 412" and I want "412" to appear in the text field.

If it matters, I'm using Acrobat Pro CC.


Thanks in advance for any assistance!

This topic has been closed for replies.
Correct answer Joel Geraci

this.path will give you the device independent path of the file including the file name. You can use standard JavaScript string operators to get from that what you want. Put that into a custom calculation script and you're good to go.

2 replies

cakeytaste
Participating Frequently
March 24, 2017

I ended up using the below. I have the second element var'd out, as that's ultimately the folder I'm going to want to populate into a text field, but I also like having the other variables set in case I want to use them, too. Do I even need the pop() at this point, since my event.value is the pathRoot? Also... is there a way to step backwards from the array, instead of forward? For instance, I'm using aPathComps[2] to get the second tier of the array, but depending on the file location, this could result in the parent folder of the folder name I want. I'd like to actually do something like select the LAST part of the array, before the file name. Guidance? try67

// Acquire folder path

var myDocPath = this.path;

// Break path into array

var aPathComps = myDocPath.split("/");

var pathRoot = aPathComps[2]; // second element

var myFilename = aPathComps[aPathComps]; // last element

// Pop off file name

aPathComps.pop();

// Populate the text field

event.value = pathRoot

try67
Community Expert
Community Expert
March 24, 2017

aPathComps[aPathComps.length-2] will return the name of the folder where the file is located.

cakeytaste
Participating Frequently
March 24, 2017

Bingo, thanks!

I was leaving off the "length" portion obviously. I appreciate the help.

Joel Geraci
Community Expert
Joel GeraciCommunity ExpertCorrect answer
Community Expert
March 23, 2017

this.path will give you the device independent path of the file including the file name. You can use standard JavaScript string operators to get from that what you want. Put that into a custom calculation script and you're good to go.

cakeytaste
Participating Frequently
March 24, 2017

Thanks for the "this.path" option. Is it possible to restrict the output to only the folder that the file is located in, instead of the entire path?

For example, using "event.value = this.path;" returns the entire server address of the file, and I only want the last folder.

(/server/users/me/PDFs/412/nameofpdf.pdf vs. 412)

try67
Community Expert
Community Expert
March 24, 2017

As mentioned, this can be done using basic string manipulation commands. Start by splitting the path using "/" as the delimiter. The last object in the resulting array is the file name, the one before that is the name of the folder where it's located.