Copy link to clipboard
Copied
Okay,
Say I have a series of folders and I have linked art and the files they are linked to all mixed up in these folders. My file structure is as such;
myFiles\HH01000-01999\HH01000-HH01099\HH001001.PDF
and now I need to change the file structure to this;
myFiles\HH\HH01000-01999\HH01000-HH01099\HH001001.PDF
adding the folder HH breaks the links.
What is the best way to identify the broken link and change its path with JSX? Anybody got any ideas?
Copy link to clipboard
Copied
This little test I did allows me to retrieve the path of each linked image.
myVar = app.activeDocument.placedItems;
for(i=0; i < myVar.length; i++) {
fileName = myVar.file.path.toString();
alert(fileName);
}
Copy link to clipboard
Copied
Does anyone know if it is possible to change the path of a linked item with a script? That seems to be my biggest problem.
Copy link to clipboard
Copied
Passing a new file is simple enough… somePlaceItem.file = File( someNewPath );
The issue you will have is if you have already moved the links to new location then you can't access the missing file object…
You would need to read the link info from the XMP metadata instead.
If you have not yet moved the files then you may be able the have script get, move, relink on the fly…
Copy link to clipboard
Copied
Thanks for the info Mark.
I have looked into it and broken links will not be a problem. We are copying the folder structure and changing the folder structure on the copy. All linked art will still point to the original source that has not been changed.
so as my script goes through and changes the links it will not have a problem.
Now I have to figure out how to evaluate the path to check for HH folder and if does not find it then change the path.
illustrations/001000-001999/001000-001099/HH001032.pdf
this path it would not find the HH folder in the path and it would need to change it to
illustrations/HH/001000-001999/001000-001099/HH001032.pdf
I'm still working on that.
Copy link to clipboard
Copied
use the file name string to search for "FolderA" and replace it with "FolderB", then build a new file with the new string
var file = File("illustrations/001000-001999/001000-001099/HH001032.pdf");
var oldFolder = "illustrations";
var newFolder = "illustrations/HH";
file = new File(file.fsName.replace(oldFolder, newFolder));
alert(file.exists);
Copy link to clipboard
Copied
Thanks Carlos,
this is how i ended up getting it done.
function changeLinkedArt () {
linkedPath = app.activeDocument.placedItems;
outcome = 0;
for(i=0; i < linkedPath.length; i++) {
linkedPathArray = linkedPath.file.path.split("/");
for(j=0; j < linkedPathArray.length; j++) {
if(linkedPathArray
outcome = 1;
}
}
if (outcome === 0) {
fileName = linkedPath.file.toString();
linkedFileArray = fileName.split("/");
for(k=0; k < linkedFileArray.length; k++) {
if(linkedFileArray
linkedFileArray
NewIndexLine = linkedFileArray.join("/");
//alert(NewIndexLine);
linkedPath.file=File(NewIndexLine);
}
}
}
outcome = 0;
}
}
modified an adobe script to open all files in a folder and run the script on all of them.
wanted to build some arrays to change all files in multiple folders but i could not get the ".getFiles( fileType );" to take a path instead of the Folder.selectDialog.
thats the only thing that bugs me.
Copy link to clipboard
Copied
Folder.getFiles( /\.(ai|pfd)$/i );