• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Script to Open Folder Automatically?

Guest
Sep 10, 2012 Sep 10, 2012

Copy link to clipboard

Copied

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

TOPICS
Actions and scripting

Views

3.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Sep 10, 2012 Sep 10, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 10, 2012 Sep 10, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Sep 10, 2012 Sep 10, 2012

Copy link to clipboard

Copied

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…

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 10, 2012 Sep 10, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 10, 2012 Sep 10, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 10, 2012 Sep 10, 2012

Copy link to clipboard

Copied

heh ok, I thought this would be easier something like removing or changing a string in a code.

found another one but not working, prob just piece of code:

var inputFolder = Folder.selectDialog( "Please select top level folder to process");
var fileList = inputFolder.getFiles();

for(i=0;i<fileList.length;i++) var docRef = app.open(fileRef);

wonder is there some kind of variable instead of Folder.selectDialog to just open all files within instead of prompoting?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 10, 2012 Sep 10, 2012

Copy link to clipboard

Copied

If you know the folder you do not need to put up a select dialog just  process the folder you know.  If you keep on loading image you may start boging down the system. Here some code I used to open files flatten then resize them to tile size copy to clipboard close no save then paste them into place into a new document I'm creating to print images on roll paper.

var currrow=0; var pasted=0;

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

                              app.load(file); //load it into documents

                              var backFile= app.activeDocument; //prepare your image layer as active document

                              flatten(); //handle layered images

                              if (backFile.width.value<backFile.height.value&&width>height ) { backFile.rotateCanvas(-90.0);  } // Rotate portraits

                              if (backFile.height.value<backFile.width.value&&height>width ) { backFile.rotateCanvas(-90.0);  } // Rotate landscapes

                              if (backFile.width.value/backFile.height.value > width/height) { backFile.resizeImage(null, height, null, ResampleMethod.BICUBIC); } // wider

                              else {backFile.resizeImage(width, null, null, ResampleMethod.BICUBIC);} // same aspect ratio or taller

                              backFile.selection.selectAll();

                              backFile.selection.copy(); //copy resized image into clipboard

                              backFile.close(SaveOptions.DONOTSAVECHANGES); //close image without saving changes

                              for (var n=0;n<copies;n++) {

                                        var x =pasted*width;

                                        var y =currrow*height;

                                        var selectedRegion = Array(Array(x,y), Array(x+width,y), Array(x+width,y+height), Array(x,y+height));

                                        doc.selection.select(selectedRegion);

                                        doc.paste(true); //paste image into masked layer your document

                                        doc.selection.select(selectedRegion);

                                        align('AdCH'); align('AdCV');

                                        doc.selection.deselect();

                                        pasted++

                                        if ( pasted==cols ) { pasted=0; currrow++; }

                                        }

                              }

var inputFolder = "~/My Documents/My Pictures/";

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

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 11, 2012 Sep 11, 2012

Copy link to clipboard

Copied

thanx JJMack,

I grabbed your code and ut function at the top to look like:

function FindAllFiles(){

var inputFolder = "~/My Documents/My Pictures"

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

}

it doesn't show errors, but also does nothing. Is that what it's supposed to do, load all files from a folder?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Sep 11, 2012 Sep 11, 2012

Copy link to clipboard

Copied

Try this:

var inputFolder = Folder( Folder.desktop + '/Output_Files' ); // Make sure this is correct for your hard coded path???

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

alert( fileList.length );

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

   

    app.open( fileList );

   

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 11, 2012 Sep 11, 2012

Copy link to clipboard

Copied

fantastic, after editing it I got exactly what I wanted. I knew this has to be short script Thanx a lot Muppet Mark!

Here's my final script in case anyone needs:

var inputFolder = Folder( Folder.desktop + '/Output_Files' ); // Make sure this is correct for your hard coded path???

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

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

   

    app.open( fileList );

   

};

One thing I didn't realise is I can't automate save for web for each opened image in a sequence of actions, so image processor pro, as someone suggested in this forum is perfect for what I needed to get accomplished. But appreciate your help, this sure will be useful.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 16, 2017 Jan 16, 2017

Copy link to clipboard

Copied

Muppet Mark​ I found your reply from an old post... and it's the basic element I need to grab files from a particular folder.. However, I'd love for it to be able to open a multi-page .pdf that I'm using from another script... I've attached below your original script on top with the working version of my Multi=page .pdf below... the multi page is asking for me to pick the file.. I want to use your script to grab the files from the folder automatically...

Can you help? - THANKS

var inputFolder = Folder('~/Desktop/Test' ); // Make sure this is correct for your hard coded path??? 

 

var fileList = inputFolder.getFiles(/\.(pdf)$/i); 

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

      app.open(fileList ); 

};

///////////////***********************////////////////////////////////////////

/// Option to open Multi - Page .pdf - added to your original script /////

var theFile = File.openDialog("Select your PDF file", "Select:*.pdf");

app.displayDialogs = DialogModes.NO;   

var check = true;   

var page = 1;   

// define pdfopenoptions;   

var pdfOpenOpts = new PDFOpenOptions;   

pdfOpenOpts.antiAlias = true;   

pdfOpenOpts.bitsPerChannel = BitsPerChannelType.EIGHT;   

pdfOpenOpts.cropPage = CropToType.MEDIABOX;   

pdfOpenOpts.mode = OpenDocumentMode.CMYK;   

pdfOpenOpts.resolution = 300;   

pdfOpenOpts.suppressWarnings = true;   

pdfOpenOpts.usePageNumber  = true;   

app.togglePalettes(); // toggle off palettes so Photoshop will not need to update them 

while (check == true) {   

  try {   

  pdfOpenOpts.page = page;   

  // open;   

  var thePdf = app.open(theFile, pdfOpenOpts);   

  page++;   

  }  

  catch (e) { check =  false };   

};  

   app.togglePalettes(); // toggle on palettes 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

LATEST

I did a search here and found this script to import all the files from a folder.

app.bringToFront();

gFilesToSkip = Array( "db", "xmp", "thm", "txt", "doc", "md0", "tb0", "adobebridgedb", "adobebridgedbt", "bc", "bct" );

var inputFolder = Folder.selectDialog("Select a folder of documents to process");

// Open Folder of Images

OpenFolder();

// Given the a Folder of files, open them

function OpenFolder() {

        var filesOpened = 0;

        var fileList = inputFolder.getFiles();

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

          // Make sure all the files in the folder are compatible with PS

                if ( fileList instanceof File && ! fileList.hidden && ! IsFileOneOfThese( fileList, gFilesToSkip )) {

                        open( fileList );

                        filesOpened++;

  }

        }

        return filesOpened;

}

// determine if this file is in the list of extensions

function IsFileOneOfThese( inFileName, inArrayOfFileExtensions ) {

  var lastDot = inFileName.toString().lastIndexOf( "." );

  if ( lastDot == -1 ) {

  return false;

  }

  var strLength = inFileName.toString().length;

  var extension = inFileName.toString().substr( lastDot + 1, strLength - lastDot );

  extension = extension.toLowerCase();

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

  if ( extension == inArrayOfFileExtensions ) {

  return true;

  }

  }

  return false;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 11, 2012 Sep 11, 2012

Copy link to clipboard

Copied

Yes I was to fast with the fingers heet to be a folder object use code like  Muppet Mark  does not have to ne on the desktop and you maght want to test ir see if it exists

var testFolder = new Folder("~/My Documents/My Pictures");

                    if (!testFolder.exists) {

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 11, 2012 Sep 11, 2012

Copy link to clipboard

Copied

thank You JJMack, I got it now!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 11, 2012 Sep 11, 2012

Copy link to clipboard

Copied

Remember if there are a great number of large images in the folder that script will tax your system....

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 12, 2012 Sep 12, 2012

Copy link to clipboard

Copied

I'll keep that in mind

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines