Skip to main content
Inspiring
August 16, 2010
Question

Process files in a directory?

  • August 16, 2010
  • 1 reply
  • 3280 views

I've successfully written a script which is actually in two parts (process files via one script and then process them again via another) The plan is to join these two scripts into one powerful überscript. However I don't know how to process files in a directory - running them as a batch process is no good as I need to control the whole process rather then lots of repeat and forget loops in a batch file. At the moment it works because I proces the files via batch file and then manually feed the second script a text file with all the files to be processed. Klunky, I know, but it works. But now I want to make the whole script more efficient. Are there any (simple) script examples of how to process more than one file at a time. Cheers.

This topic has been closed for replies.

1 reply

Muppet_Mark-QAl63s
Inspiring
August 16, 2010

You have a 'folder object' that you can either have a user select at runtime or hard code a path to. From that there is a function getFiles() to which you can pass a 'mask' to filter the results for files of a specific type etc. Once you have your list you should just be able to iterate thru the array of files in a loop… Other than that I think you will need to be a little more specific on what it is that you are trying to process…

#target photoshop app.bringToFront(); // A hard coded path to a directory 'mac style' var processFolder = Folder('~/Desktop/Process Images/'); // Use folder object get files function with mask 'a reg ex' var fileList = processFolder.getFiles(/\.(jpg|tif|psd|eps|png)$/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      if (fileList instanceof File) {           open(fileList);      } }

Just added you a very basic example…

Inspiring
August 16, 2010

To add to Muppet Mark's post. Using a file mask in getFiles() is optional. Using one let's you process only the format types you select with the selection being done by getFiles(). That is something that Automate Batch can not do.

If you don't use a file mask getFiles() returns everything in the folder. Images, system, and hidden files as well as subfolders. So if you don't use a file mask you will also need some test to make sure that the file can be opened in Photoshop before the open(fileList); line.