How to Combine 2 scripts into 1

I’m still pretty green and I cannot seem to get the Order Of Operations down.

I have this Script that works

var sc = "/";
var searchString1 = /\d{7}/;
var searchString2 = /(\d)(\d)(\d)/;
var first = "000000";
var last = "999999";
var folderPrefix = sc + sc + "ad" + sc + "fs1" + sc + "gemini" + sc + "layout" + sc + "plaques_layout" + sc + "PDF" + sc;

var strEnter=prompt("Open file # (a 7-digit number)", "");

if (strEnter != null && searchString1.test(strEnter) === true) {
var str = null;
var arr = strEnter.match (searchString2);
var folder1 = shorten (arr[1], first) +"-"+ shorten (arr[1], last) + sc;
var folder2 = shorten (arr[1]+arr[2], first) +"-"+ shorten (arr[1]+arr[2], last) + sc;
var folder3 = shorten (arr[1]+arr[2]+arr[3], first) +"-"+ shorten (arr[1]+arr[2]+arr[3], last) + sc;
var folderString = (folderPrefix + folder2  + folder3); //alert(folderString);
} else { alert ("invalid input: " + strEnter); }

function shorten (strt1, num) {
str = strt1 + num;
return str = str.slice(0, 7);
}

var myFile= new File(folderString + sc + strEnter + ".pdf");
if (myFile.exists) {app.open(myFile);
} else { alert ("File Not Located");}

However, I need var folderPrefix to be an array so it can find the file in 1 of 4 folderPrefix locations. Can anyone assist me with that please?

This is the 2nd piece of Scripting

    // you must first have set each of these
var path1 = sc + sc + "ad" + sc + "fs1" + sc + "gemini" + sc + "layout" + sc + "plaques_layout" + sc + "PDF" + sc;
var path2 = sc + sc + "wa1-fs-01" + sc + "public" + sc + "WA-Plaque Art Layouts" + sc + "WA-PDF's" + sc;
var path3 = sc + sc + "can-fs-vm01" + sc + "Public" + sc + "plaque_layouts" + sc + "PDF" + sc;
var path4 = sc + sc + "IDP-FS-02" + sc + "DATA" + sc + "Graphics" + sc + "Plate_Layouts" + sc + "Proofs" + sc;

    //make array of paths
var folderPrefix = [path1, path2, path3, path4];

    //will return first valid file path
var locFile = getFileInPaths(strEnter, folderPrefix);

if (locFile != undefined) {
    // now open locFile
}

    // this is a function that gets called by code above
function getFileInPaths(fileName, paths) {
$.writeln(fileName);
    // declare this vars, but don't assign value (it will be undefined)
    var myPath;

    // keep trying a path until no paths left, or file exists
    while (myPath = paths.shift()) {
        $.writeln('myPath+fileName = ' + myPath + fileName);
        var myFile = File(myPath + fileName)
        if (myFile.exists) return myFile;
    }

    // no valid file found
    alert('No valid file found in paths')
    return;
}

Thank you in Advance!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.