Copy link to clipboard
Copied
Hello all,
I am trying to write a script to automate relinking broken links.
The idea is to make a list of all broken links, then search for those in a particular directory. There is no easy way of searching a directory with javascript that i know of.
I tried making an array populated with all ai files in a particular tree structure but i hit stack overflow rather quickly.
Any thoughts about how one could search in directories?
below is all i have.
var idDoc = app.activeDocument
var broke = []
var foundFiles = []
var folds = []
var started = false
for (var i=0; i < idDoc.links.length; i++){
var a = idDoc.links
if (a.status == LinkStatus.LINK_MISSING ){
broke.push(a.name)
}
}
if (broke.length >= 0){
var searchFolder =Folder("Q:\Kollektion_Files")
var folderCount = []
getFilesFromFolder(searchFolder)
fix(broke, foundFile)
}
function getFilesFromFolder(curfolder){
if (started == true){
folds.splice(0,1)
}
var files = curfolder.getFiles();
for (l = 0; l < files.length; l++){
if (files
var entry = files
folds.push(entry)
}
}
var curFile;
for(var x=0; x<files.length; x++){
curFile = files
if(curFile instanceof File && validFile(curFile)){
foundFiles.push(curFile);
}
}
started = true
var len = folds.length
if (folds.length >=0){
getFilesFromFolder(folds[0])
}
}
Thanks.
Dane
Copy link to clipboard
Copied
Check out this script.
— Kas
Copy link to clipboard
Copied
mornin' Kas
I just went through this application. Very interesting. I think I learned a dozen new things.
I did actually manage to pound out a refined search using parts of the old path name.
One of the main goals of the script though, was to have no dialogs. The script would just figure out where to go(with in a defined area)
Below is the code I ended up with.
Thanks a lot for your input and share this great bit of scripting.
Copy link to clipboard
Copied
One of the main goals of the script though, was to have no dialogs.
In this case you may be interested in my Batch processor script so instead of opening, processing the current document, closing it, you may process dozens/hundreds/thousands files in one go. I am working on a new -- much improved -- version now. Last week I tested it together with my new 'package' script at work to make archive of old issues and it worked well for me: packaged almost 300 files for 16 minutes.
— Kas
Copy link to clipboard
Copied
Excellent.
Get stuff.
I'd sure like to be spending more time writing scripts and less time using them. Far more interesting.