Skip to main content
September 10, 2012
Question

Script to Open Folder Automatically?

  • September 10, 2012
  • 2 replies
  • 4450 views

Good day,

I've been searching the net for 2 days for something probably simple, but can't find it.

Is there a script that can open all files within a folder automatically?

What I want to do is to have Photoshop open a folder full of files, save each one for web. I can automate save for web part with actions. but can't find a way to import a folder.

Image processor is great, except one thing that annoys the hell out of me which is dialog popup. So I'm looking for script that automatically, without any dialog boxes, opens up all files within a folder.

I found this:

var dir = Folder('Q:/Images');

var selectedFile = dir.openDlg("Select Image" , "Select:*.nef;*.cr2;*.crw;*.dcs;*.raf;*.arw;*.orf;*.dng;*.psd;*.tif;* .jpg;*.png;*.bmp");

if( selectedFile !=null ){open(File(selectedFile));}

but it's a prompt. Is there some script that just loads a folder with files automatically?

thanx

This topic has been closed for replies.

2 replies

Inspiring
September 10, 2012

The folder object has a getFiles() method which you can pass a regexp to filter otherwise it will return all files… Lots of samples of this here in this forum…

September 10, 2012

thanx, but I just need it to open up all files in a folder. They're all dataset files from photoshop.

JJMack
Community Expert
Community Expert
September 10, 2012

Files can be opened, placed, executed, deleted etc in my loop I was placeing files not opening

                              // Loop Image File Start

                              var fileList = inputFolder.getFiles(/\.(nef|cr2|crw|dcs|raf|arw|orf|dng|jpg|tif|psd|eps|png|bmp)$/i);

                              // Loop through files

                              for (var i = 0; i < fileList.length; i++) {

                                        // Only process the returned file objects

                                        // The filter 'should' have missed out any folder objects

                                        //  get next image file

                                        if (fileList instanceof File) {

                                                  //alert(fileList);

                                                  var layers = activeDocument.layers;

                                                  activeDocument.activeLayer = layers[layers.length-1-imageNumber+1];           // Target Background Layer or last placed image

                                                  placeImage(fileList);                                                     // Place in Image   you would open instead of place

                                                  // Get Smart Object current width and height


JJMack
JJMack
Community Expert
Community Expert
September 10, 2012

I'm sure if you look at a script like the Image Processor that ships with Photoshop you will see code to do that. You can just point it at a folder and it will process all the image files it it. There is also a option to process sub foldere so it may show you how to use recursion.

I quick look I found this in Image Processor

///////////////////////////////////////////////////////////////////////////////

// Function: FindAllFiles

// Usage: Find all the files in the given folder recursively

// Input: srcFolder is a string to a folder

//                      destArray is an Array of File objects

// Return: Array of File objects, same as destArray

///////////////////////////////////////////////////////////////////////////////

function FindAllFiles( srcFolderStr, destArray ) {

          var fileFolderArray = Folder( srcFolderStr ).getFiles();

          for ( var i = 0; i < fileFolderArray.length; i++ ) {

                    var fileFoldObj = fileFolderArray;

                    if ( fileFoldObj instanceof File ) {

                              destArray.push( fileFoldObj );

                    } else { // folder

                              FindAllFiles( fileFoldObj.toString(), destArray );

                    }

          }

          return destArray;

}

To do what you want I've used code that looks like this

// Loop Image File Start

                              var fileList = inputFolder.getFiles(/\.(nef|cr2|crw|dcs|raf|arw|orf|dng|jpg|tif|psd|eps|png|bmp)$/i);

                              // Loop through files

                              for (var i = 0; i < fileList.length; i++) {

JJMack
September 10, 2012

thank You JJMack, but I don't see where I tell the script which folder to open up.

My path is "C:\Users\Admin\Desktop\Output_Files", so I tried putting that instead of srcFolderStr or Folder, but nothing happens. Well probably cause I have no idea what I'm doing. No scripting knowledge here.