Print Page | Close Window

Looping Code Error looking for a document

Printed From: Foxit's Planet PDF Forum
Category: Lets Talk PDF
Forum Name: JavaScript
Forum Description: Discussions relating to the use of JavaScript within PDF.
URL: http://forums.planetpdf.com/forum_posts.asp?TID=1109
Printed Date: 23 Apr 2019 at 1:37am
Software Version: Web Wiz Forums 11.10 - http://www.webwizforums.com


Topic: Looping Code Error looking for a document
Posted By: Doc_45
Subject: Looping Code Error looking for a document
Date Posted: 19 Feb 2014 at 4:29am
The following code generates an error when checking to see if a document exists. I have highlighted the section with stars where it is falling over. This code worked for years then stopped, then 6 months ago started again. I assumed Adobe playing around with security issues.

Any clues would be appreciated, as I am a newby and taught myself this code.


function GAddDP()
{
     var aFiles = new Array("_Map_A.pdf","_Map_B.pdf","_Map_C.pdf","_Map_D.pdf","_Map_E.pdf","_Map_F.pdf","_Demo.pdf","_Bus.pdf","_Spend.pdf");
     var cnewfile = new Array(8)

     var aPathComps = this.path.split("/");               // Path
     var myFileName = aPathComps.pop();               // Filename
     var fileNmRoot = myFileName.split(".").shift();          // Root Filename
     var strNewPath = aPathComps.join("/");               // Append path to File to Insert

for ( var i=0; i < aFiles.length; i++) {               // Loop through Array
     var fileNmNew = fileNmRoot + aFiles               // File to Insert
     //console.println(fileNmNew);
     cnewfile = strNewPath + "/" + fileNmNew          // Combine All
     //console.println(cnewfile);
     }
//**************************************************************
for ( var i=0; i < cnewfile.length; i++) {               // Loop through the list of filenames
     var nfileexists = 1;
     try{
     var otherDoc = app.openDoc(cnewfile);          // Test if File exists
     }catch(e){
        nfileexists = 0;                         // Catch the errror if it doesnt
     }
//**************************************************************
if (nfileexists > 0)
     {
     otherDoc.closeDoc();                              // If it exists close it
     this.insertPages({nPage:this.numPages-1,cPath:cnewfile});     // Insert the document if it exists
     }
     }
//*** Front Cover
     var fileNmNew2 = fileNmRoot + "_Cover.pdf"          // File to Insert
     var cnewfile2 = strNewPath + "/" + fileNmNew2          // Combine All
try{
     var nfileexists = 1
     var otherDoc = app.openDoc(cnewfile2);
     }catch(e){
        nfileexists = 0;
     }
if (nfileexists > 0)
     {
     otherDoc.closeDoc();
     this.insertPages({nPage:-1,cPath:cnewfile2,nStart: 0 });
     }
app.alert({cMsg: "     Data Pack Append Completed !",cTitle: "Geotech Data Packs"});
}

Thanx Mark




Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.10 - http://www.webwizforums.com
Copyright ©2001-2017 Web Wiz Ltd. - https://www.webwiz.net