Skip to main content
Inspiring
January 29, 2010
Answered

lastIndexOf ("/") InDesign CS4 JavaScript

  • January 29, 2010
  • 1 reply
  • 1570 views

Hi,

I need lastIndexOf ("/") of myDocPath, but the line gives me error all the time. Is it because of '/', but shouldn't it be perceived as a string since it's in the double quotes. Here is my script:

var myDoc = app.activeDocument;
var myDocPath = myDoc.path;
var myFolderSplit = myDocPath.lastIndexOf ("/")

and it brakes at the green line. How can I get around it.

Thank you very much for your help.

Yulia

This topic has been closed for replies.
Correct answer Kasyan Servetsky

Do you want to get path to the folder in which myDoc is located?

1 reply

Kasyan Servetsky
Legend
January 29, 2010

Document doesn't have path property. However, I don't understand what you want to get in myFolderSplit .

var myDoc = app.activeDocument;
var myDocPath = myDoc.filePath.absoluteURI;
var myFolderSplit = myDocPath.lastIndexOf("/");

YuliaartAuthor
Inspiring
January 29, 2010

I need the part of the path to the last '/' and index of it should give me the number of characters in the path to that point.

YuliaartAuthor
Inspiring
January 29, 2010

Thank you, it works now.