Search for primary file + Sub-folders

Okay, I know how to locate a specific file in a specified place; but now I need a way to locate a specific file in a general situation.  Basically I have a library of textures with their exact file name.  Well, I still don't know their exact location.  For example, I have to run through my script "brushed_aluminum.jpg" textures, but I don't know exactly where it is, I just know that it's somewhere in my file textures (c:\textures\ for the sake of simplicity).  Now, in c:\textures\ there are several subfolders (and possibly sub-sub-folders, etc.) it might be in.  How would I go to have the script to find the file in this location, then get his exact path and store the exact path + name of file to a variable?  Thanks for any help!

dgolberg

Edit: I had 2 other questions, but I was able to resolve myself.

Adding 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[a].split(',');
for(var z in folders){//loop through all folders to find file
    var file = File(folders[z] + "/"+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[i];
  if ( fileFoldObj instanceof File ) {
  } else {
         destArray.push( Folder(fileFoldObj) );
  FindAllFolders( fileFoldObj.toString(), destArray );
  }
 }
 return destArray;
};
main();

Tags: Photoshop

Similar Questions

Maybe you are looking for

  • I'm trying to translate an English page and can not find the command. Anyone know where it is?

    I try to access a Web site for more information and the link takes me to a page in a pictographic language (Japanese, Chinese, Korean). I can't find out how to ask Google or Firefox to translate the page in English. Someone knows how to do this? Than

  • WebSocket on Windows 8 bad work.

    I try to test websocket support Firefox 16.1. open http://www.websocket.org/echo.html2. click on 'Connect'-> socket properly open Web3. click on 'Send'-> packet sent, but receaved no answer.4. click on 'Send' 3-7 times. -> Profit. Firefox receaved th

  • The "Buck" has to stop SOMEWHERE!

    "First of all, I know that SCEA is a real different company but when I expereince questions there I'm not going ' ah, gosh darn it Sony Computer Entertainment Of AMerica '... I say "Frekanin Sony!" Now, this must face a society that Sony authorizes b

  • 2009 build exe error

    I f3 2009 installed on an XP sp3 machine and I am trying to build an executable and get the error below.  I can find the error.llb and the vi in question.  I opened it even without any problem. I've included the vi I'm turning into an exe file, thoug

  • HP OfficeJet Pro 8600 N911a - two-sided copies

    I'm eager to take a two originals face and make a copy of both sides.  When I press the ECO button it says that this option is disabled.  I can't understand how to turn it on.