Skip to main content
November 14, 2013
Answered

How to capture image name from the file path of the links in indesign

  • November 14, 2013
  • 2 replies
  • 2033 views

Hi,

I am capturing the complete path of links used in indesign through javascript. However, I need to capture only the image name from the file path.

For example:

Through script I am capturing the path of this image as:

/Users/user-name/Desktop/image.ps

However, I need to capture from this path only the image name i.e. I want only image.ps

I tried doing grep, replace but not too sure how to carry forward.

Any help will be appreciated.

Here is my script through which I am getting the link path.

var myDoc = app.activeDocument;

var myLinks = myDoc.links;

if (myLinks.length == 0) {

     ErrorExit("This document doesn't contain any links.", true);

}

for (var i = myLinks.length-1; i >= 0 ; i--) {

var currentLink = myLinks;

var LinkPath = currentLink.filePath;

alert (LinkPath);

}

}

Regards,

Abhi

This topic has been closed for replies.
Correct answer Jump_Over

Hi,

Call displayName from a file:

var fileName = File(LinkPath).displayName;

Jarek

2 replies

Jump_Over
Jump_OverCorrect answer
Legend
November 14, 2013

Hi,

Call displayName from a file:

var fileName = File(LinkPath).displayName;

Jarek

November 14, 2013

Thank you!!

It works!!

Regards,

Abhishek

Inspiring
November 14, 2013

try this

alert (LinkPath.split ('\\').pop());

Inspiring
November 14, 2013

What is wrong with

var linkname=currentLink.name;

Ralf

November 14, 2013

Thank you!!

It really helps!

Regards,

Abhishek