Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
0

lastIndexOf ("/") InDesign CS4 JavaScript

Participant ,
Jan 29, 2010 Jan 29, 2010

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

TOPICS
Scripting
1.5K
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

Valorous Hero , Jan 29, 2010 Jan 29, 2010

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

Translate
Valorous Hero ,
Jan 29, 2010 Jan 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("/");

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
Participant ,
Jan 29, 2010 Jan 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.

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
Participant ,
Jan 29, 2010 Jan 29, 2010

Thank you, it works now.

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
Valorous Hero ,
Jan 29, 2010 Jan 29, 2010

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

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
Participant ,
Jan 29, 2010 Jan 29, 2010

Actually I am saving it into the folder that is one step up in the Finder system.

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
Valorous Hero ,
Jan 29, 2010 Jan 29, 2010

var myDoc = app.activeDocument;
var myFilePath = myDoc.filePath;
var myParentFolder = myFilePath.parent;
var myNewFile = new File(myParentFolder.absoluteURI + "/" + myDoc.name);
myDoc.save(myNewFile);

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
Participant ,
Jan 29, 2010 Jan 29, 2010
LATEST

WOW! how elegant, I definitely went the hard way. Thank  you so much.

Yulia

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