Adding to the last example...
function main(){
var Path = File($.fileName).parent;
var csvFile = File(Path + "/csvFile.csv");//csv file
var errorLog = File(Path + "/errors.txt");//error log
$.os.search(/windows/i) != -1 ? errorLog.lineFeed = 'windows' : errorLog.lineFeed = 'macintosh';
if(!csvFile.exists){
alert("Unable to find CSV file!");
return;
}
var sourceFolder = Folder.selectDialog("Please select Folder where files are to be found");
if(sourceFolder == null) return;
var folders =[];
folders = FindAllFolders(sourceFolder, folders); //get a list of all sub folders
folders.unshift(sourceFolder);
csvFile.open('r');
var data=[];
csvFile.readln(); //do not process the header line
while(!csvFile.eof){
var line = csvFile.readln().replace(/^\s+|\s+$/g, ''); //remove leading and trailing spaces
if(line.length>3) data.push(line); //Make sure it's not a blank line
}
csvFile.close();
for(var a in data){//process your files
var bits = data.split(',');
for(var z in folders){//loop through all folders to find file
var file = File(folders + "/"+bits[0]);
if(file.exists) break;
}
if(!file.exists) {//if file not found it is logged in error file.
errorLog.open('e');
errorLog.seek(0,2);
errorLog.writeln(bits[0] + " could not be found");
errorLog.close();
continue;
}
//open (file);
//runaction
//app.doAction(bits[1].toString(), bits[2].toString());
//do whatever
//save and close you document
alert(file +"\r will be running action - " + bits[1].toString() + " actionSet = " + bits[2].toString() );
}
}
function FindAllFolders( srcFolderStr, destArray) {
var fileFolderArray = Folder( srcFolderStr ).getFiles();
for ( var i = 0; i < fileFolderArray.length; i++ ) {
var fileFoldObj = fileFolderArray;
if ( fileFoldObj instanceof File ) {
} else {
destArray.push( Folder(fileFoldObj) );
FindAllFolders( fileFoldObj.toString(), destArray );
}
}
return destArray;
};
main();