Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Getting The List Of Image Files In A Directory With Photoshop Scripting

** TL;DR

This function returns a list of image files in a given directory:

Code

function getImages(sourceDir) {
  const files = new Array()
  const rawFiles = Folder(sourceDir).getFiles()
  for (var i = 0; i < rawFiles.length; i++) {
    if (rawFiles[i].name.match(/\.(psd|jpg|gif|png)$/i) !== null) {
      files.push(rawFiles[i])
    }
  }
  return files
}

Then call it like this:

Code

const fileList = getImages('/some/directory/path')