Skip to main content
Known Participant
May 16, 2013
Question

Subfolders/Folders Issue

  • May 16, 2013
  • 1 reply
  • 1123 views

So I am trying to get a handle on getFiles and folder structure.

Currently I have a script that works fine, except it runs repetitively due to how I have my folder call setup. I'm uncertain how to get past it, because it has some functionality I need and frankly I'm new at using .js on folder structures.

So I have a target folder, tFolder, and within this, subfolders to run through the script. Within these folders are .psd files that have a count of 3-5 files.

Currently the script iterates through each file, however many files are in the subfolder, which of course isn't ideal. Could someone help with a modification of the script below? .pop seemed to be the right direction but I couldn't get it to work in this case.

try{
       var tFolder = Folder.selectDialog("Select the folder with PSDs to process");
        var mainFldr = tFolder.path;

}
catch(error){
    alert("User Cancelled Folder Selection")
    }   

try {
           if (tFolder != null)  processFolder(tFolder);

            function processFolder(folder) {
                var fileList = folder.getFiles()
                 for (var i = 0; i < fileList.length; i++) {

                        if (fileList instanceof File && fileList.name.match(/\.(psd)$/i)) {
                            fileOpen(fileList, i);
                                                }

////// This is the area  I know I need to rewrite, but I cannot figure out a way to modify this correctly//////////

                    else if (fileList instanceof Folder) {                       
                       
                   processFolder(fileList);


                        }
                    }
                }
  
   }
    catch(error){
        alert(String("Error in parent process \n"+error))
  
}  

This topic has been closed for replies.

1 reply

vinoth_mannu
Inspiring
May 17, 2013

Hi Paul,

This was really useful, In addition

Could you please suggest for saving the files in different folder.retaining the same structure of the input folder

For ex - var inputFolder = Folder ( 'D:/Work/In/');

Sub folders may be 1,2,,3

Saving the files in

var outputFolder = Folder( ['D:/Work/out/'] ); with same Sub folders may be 1,2,,3

Regards,

Vinoth

Paul Riggott
Inspiring
May 17, 2013

These might help as both support keeping folder structure...

Image Processor Pro

http://russellbrown.com/scripts.html

Picture Processor

http://www.scriptsrus.talktalk.net/PP.htm