• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

How to replace path of an illustrator file to a new one using ExtendScript ?

New Here ,
Apr 10, 2023 Apr 10, 2023

Copy link to clipboard


Hi! I have a problems with one script... i need a simple thing - replacing one path of the file to another.
Its really easy for any footage, (little harder for sequence, but still possible).
How to do this with illustrator/photoshop files that contain layers? If im apply the usual method to them, which I wrote below, then all layers in my project will be replaced with a single file. How to just replace the path, with keep separating the layers in my project ?
I should note that the .ai (or .psd) file in the old path and in the new one are absolutely identical just different path.

// get the current project
var curProject = app.project;

// create undo group
app.beginUndoGroup("Replace Illustrator Footage Path");

// iterate through all the items in the project
for (var i = 1; i <= curProject.numItems; i++) {
var curItem = curProject.item(i);
// check if the item is an Illustrator file
if (curItem.file instanceof File && curItem.file.name.match(/\.ai$/i)) {
// replace the file path
var curFilePath = curItem.file.fsName;
var newFilePath = new File("C:\\Users\\Alienware\\Downloads\\test PbyBM folder\\new\\" + curItem.file.name);
// alert the user that the file path has been updated
alert("File path updated.");

// close undo group


Error or problem , FAQ , How to , Import and export , Scripting






Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation