forked from ff6347/mpo-id-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
relink-missing-files.jsx
80 lines (65 loc) · 2.02 KB
/
relink-missing-files.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
(function(thisObj){//based on RelinkLinksOfBookDocs2NewPath_inSubfolder2.js
// found on http://www.hilfdirselbst.ch/foren/Nach_fehlenden_Verkn%FCpfungen_suchen_ersetzen_-_auch_in_Unterordner_P255698.html
// if (app.books.length > 1){
// myBook = myBookSelect();
// }
// else {
// // Wiederholung des Öffnen-Dialogs so lange keine Buchdatei geöffnet ist
// while (app.books.length <1){
// var myBookFile = File.openDialog("Wähle eine Buchdatei");
// var myBook = app.open(File(myBookFile));
// }
// myBook = app.books[0];
// }
main();
function main (){
var topFolder = Folder.selectDialog ("Choose a Folder...");
var fileandfolderAr = scanSubFolders(topFolder);
// var myDocs=myBook.bookContents;
// for (oneDoc=0; oneDoc<myBook.bookContents.length; oneDoc++){
// öffne Dokument "oneBook" des Buches
myDoc = app.activeDocument;
if(!myDoc) {
alert("please open a document");
return;
}
var missedones = 0;
myLinks = myDoc.links;
for (oneLink=myLinks.length-1;oneLink>-1;oneLink--) {
myLink = myLinks[oneLink];
if(myLink.status == LinkStatus.LINK_MISSING){
myName = String(File.encode(myLink.name));
missedones++;
for (var c = 0; c < fileandfolderAr[1].length; c++){
var myNewLink = File(fileandfolderAr[1][c]+ "/" + myName);
try{
myLink.relink(myNewLink);
myLink.update();
}
catch(e){
}
}
}
}
// Dokument schließen - Sichern ohne zu fragen
// myDoc.save();
// myDoc.close(SaveOptions.yes);
// }
alert("Ready.\nRelinked "+missedones+" Files.");
}
function scanSubFolders(tFolder)
{
var sFolders = [];
var allFiles = [];
sFolders[0] = tFolder;
for (var j = 0; j < sFolders.length; j++) // loop through folders
{
var procFiles = sFolders[j].getFiles();
for (var k=0;k<procFiles.length;k++) // loop through this folder contents
{
if (procFiles[k] instanceof File) allFiles.push(procFiles[k]);
else if (procFiles[k] instanceof Folder) sFolders.push(procFiles[k]);
}
}
return [allFiles,sFolders];
}})(this);