Skip to main content
Known Participant
March 12, 2020
Question

find a file based on its extension name: ExtendScript - Photoshop

  • March 12, 2020
  • 2 replies
  • 932 views

Hi Community, this is my first week using ExtendScript. I have been able to pretty quickly create a lot of powerful little scripts but this is alluding me for some reason...  What I am trying to do after opening a Tiff file is look in that same directory for any files of a specific extension like .jpg, just to see if they are present. The jpg's in this case have a bunch of metadata that needs to follow the Tiff. Maybe it is the 50 hours I have spent staring at Javascript this week already but I am not getting any examples I find to work. Any help would be greatly appreciated. 

This topic has been closed for replies.

2 replies

Chuck Uebele
Community Expert
Community Expert
March 14, 2020

That's a lot of extra stuff if you just want the get the path of the active document. 

 

var docPath = activeDocument.path;

Chuck Uebele
Community Expert
Community Expert
March 13, 2020

This is how to create an array of files with a jpg extension. Then you can create a loop and go through the files in the array.

 

var imageFolder = new Folder('~/desktop/')// put image path here
var mask = '*.jpg';
var fileList = imageFolder.getFiles (mask);
Known Participant
March 13, 2020

Thanks that was helpful. I think the pathing was tripping me up. This got me exactly what I need:

var myPath = (app.activeDocument.fullName.parent.fsName).toString().replace(/\\/g, '/');
var imageFolder = new Folder(myPath)
var mask = '*.png';
var fileList = imageFolder.getFiles (mask);
alert(fileList);