Photoshop javascript: Open files in all subfolders
hi guys
i'm new javascript, , general photoshop scripting. script coming on well, struggle working files , folders. it's lack of basic javascript knowledge, need work on. right now, i'm trying expand image open part of script, opens images regardless of whether in subfolder or not.
you can see input folder (c:/input). want able throw files in there, in folders, not. out of interest, outputs combined 1 output folder... bit fine.
var infolder = new folder("c:/input")
if(infolder != null){
var filelist = infolder.getfiles(/\.(jpg|tif|psd|bmp|gif|png|)$/i);
}
for(var = 0 ;a < filelist.length; a++)
{
var docref = open(filelist[a]);
//do things here
}
is there easy way of expanding include files in subfolders? advice appreciated.
thanks
david
folder.getfiles() works 1 folder @ time. files in folder in subfolders need scan each subfolder. 1 way recursive function. this:
var topfolder = new folder('~/desktop/test'); var fileandfolderar = scansubfolders(topfolder,/\.(jpg|tif|psd|bmp|gif|png|)$/i); alert('scan of ' + topfolder.fullname + '\n' + fileandfolderar[0].length + ' files\nlast file: ' + decodeuri(fileandfolderar[0][fileandfolderar[0].length-1])); alert('scan of ' + topfolder.fullname + '\n' + fileandfolderar[1].length + ' folders\nlast folder: ' + decodeuri(fileandfolderar[1][fileandfolderar[1].length-1])); function scansubfolders(tfolder, mask) { // folder object, regexp or string var sfolders = new array(); var allfiles = new array(); sfolders[0] = tfolder; (var j = 0; j < sfolders.length; j++){ // loop through folders var procfiles = sfolders[j].getfiles(); (var i=0;i<procfiles.length;i++){ // loop through folder contents if (procfiles[i] instanceof file ){ if(mask==undefined) allfiles.push(procfiles[i]);// if no search mask collect files if (procfiles[i].fullname.search(mask) != -1) allfiles.push(procfiles[i]); // otherwise match mask }else if (procfiles[i] instanceof folder){ sfolders.push(procfiles[i]);// store subfolder scansubfolders(procfiles[i], mask);// search subfolder } } } return [allfiles,sfolders]; };
More discussions in Photoshop Scripting
adobe
Comments
Post a Comment