Copy link to clipboard
Copied
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
Do you want to get path to the folder in which myDoc is located?
Copy link to clipboard
Copied
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("/");
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thank you, it works now.
Copy link to clipboard
Copied
Do you want to get path to the folder in which myDoc is located?
Copy link to clipboard
Copied
Actually I am saving it into the folder that is one step up in the Finder system.
Copy link to clipboard
Copied
var myDoc = app.activeDocument;
var myFilePath = myDoc.filePath;
var myParentFolder = myFilePath.parent;
var myNewFile = new File(myParentFolder.absoluteURI + "/" + myDoc.name);
myDoc.save(myNewFile);
Copy link to clipboard
Copied
WOW! how elegant, I definitely went the hard way. Thank you so much.
Yulia
Find more inspiration, events, and resources on the new Adobe Community
Explore Now