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

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

Explorer ,
Mar 12, 2020 Mar 12, 2020

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. 

955
Translate
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 ,
Mar 12, 2020 Mar 12, 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);
Translate
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 ,
Mar 13, 2020 Mar 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);
Translate
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 ,
Mar 13, 2020 Mar 13, 2020
LATEST

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

 

var docPath = activeDocument.path;

Translate
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