1 Reply Latest reply on Aug 20, 2015 6:25 PM by JJMack

    Need help searching through sub-directories

    pharmon_

      I need to search through multiple subdirectories, which contain exactly 2 images in each. One original image and one possible updated image.


      I then need to compare the 2 images newLayer.blendMode = BlendMode.DIFFERENCE; and log whether there are differences or not.


      I cannot figure out how to recurse through subdirectories properly.  My current script looks like this:


      #target photoshop

       

      function main() {

       

          var errorlog = File(Folder.desktop + "/Test_Log.txt");

          var d =new Date;

      //    errorlog.open('w');// write

          errorlog.open('a');// append

          errorlog.writeln(d); // date

       

      // This section shows how to set up user selected images

          var mySelectFile1 = File.openDialog("Selection prompt");

          if(mySelectFile1 != null) app.open(mySelectFile1);

       

          var mySelectFile2 = File.openDialog("Selection prompt");

          if(mySelectFile2 != null) app.open(mySelectFile2);

       

      // Making the selected images variables

          var doc1 = app.open(mySelectFile1);

          var doc2 = app.open(mySelectFile2);

       

      // Selecting entire doc2 image and copying

          doc2.selection.selectAll();

          doc2.selection.copy();

       

      // Setting doc1 to active document

          app.activeDocument = doc1;

       

      // Pasting doc2 into new layer in doc1

          var newLayer = doc1.paste();

       

      // Selecting the difference BlendMode option in layers

          newLayer.blendMode = BlendMode.DIFFERENCE;

       

      // Checking histogram to see if there is any difference between layers (doc1 as background and doc2 as new layer)

          found=0

          var histogram = doc1.histogram;

          for (var i = 1; i < histogram.length; ++i) {

              if (histogram[i] > 0)

                  found=1

          }

       

      // log output

          if (found) {

              errorlog.writeln(doc1.name + "," + doc2.name  + ",Differences_Found")

              }

       

          else {

              errorlog.writeln(doc1.name + "," + doc2.name  + ",Exact_Match")

              }

       

      // close all open documents without saving

          while (documents.length > 0) {

              activeDocument.close(SaveOptions.DONOTSAVECHANGES);

      }

       

          errorlog.close();

          errorlog.execute();

          return;

      }

       

      main ()

       

      Thank you.

        • 1. Re: Need help searching through sub-directories
          JJMack Most Valuable Participant

          Yes your folders contain image files and sub folders you need to use recursion to process the sub folders.

           

          Here is a very simple script I use to clear out my slide show folder it contains  images and sub folders.  Its use by my slide show action. The action clears out he slideshow folder on my desktop then uses the Image Processor Pro plug-in script  process all the images in my desktop source images folder,  To create the slide shows for the various devices I use for displaying image in a slide show.  Galaxy tab display 16:10 sideshow 2560x1600 and also as a 3:2 slide show 2400x1600.  Surface Pro 3   sideshow 3:2   2160x1440, iPo4 4 Slide show 3:2  960x640, HDTV 1920x1080 and 4kTV 3840x2160. I take a coffee break...

           

          #target photoshop

          app.bringToFront();

           

           

          var TreeRoot = '~/Desktop/SlideShows';

          clearTree(TreeRoot)

          app.togglePalettes();

           

           

          function clearTree(tFolder) { // folder object

              var sFolder = new Folder(tFolder);

              if (sFolder.exists) {

                   var procFiles = sFolder.getFiles();

                         for (var i=0;i<procFiles.length;i++){                                    // loop through this folder contents

                             if (procFiles[i] instanceof File ){ procFiles[i].remove(); }        // Delete  File

                            else if (procFiles[i] instanceof Folder){ clearTree(procFiles[i]); } // search the subfolder

                            }

                   }

            };