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

Trying to get the names of Images in a Folder

New Here ,
May 10, 2023 May 10, 2023

Hey, I am trying to get the names of images in a Folder. Tried using a script like this but got an error saying folder.getFiles is not a function. How can I do this ?

"""

var myFolder = Folder.selectDialog();
alert(myFolder)
    if(folder != null)
    {
        var files = folder.getFiles(/\.(jpg|jpeg|png|gif)$/i);
        alert(files.length)
    //     for(var i = 0; i < files.length; i++)
    //     {
    //         var file = files[i];
    //         if(file instanceof File && )
    //     }
    }
""""
TOPICS
How to , Scripting , UXP Scripting
376
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

correct answers 1 Correct answer

Community Expert , May 10, 2023 May 10, 2023

Hi @Victor29751988fsbx , You defined the myFolder variable, but then referenced an undefined variable folder. Try this:

 

var fldr = Folder.selectDialog("Select the folder containing the images", ""); 
var na = []
if(fldr != null){ 
    var fa = fldr.getFiles(/\.(jpg|jpeg|png|gif)$/i); 
    for (var i = 0; i < fa.length; i++){
        na.push(fa[i].name)
    };   
}

$.writeln(na)
//returns an array of file names

 

Translate
Community Expert ,
May 10, 2023 May 10, 2023
LATEST

Hi @Victor29751988fsbx , You defined the myFolder variable, but then referenced an undefined variable folder. Try this:

 

var fldr = Folder.selectDialog("Select the folder containing the images", ""); 
var na = []
if(fldr != null){ 
    var fa = fldr.getFiles(/\.(jpg|jpeg|png|gif)$/i); 
    for (var i = 0; i < fa.length; i++){
        na.push(fa[i].name)
    };   
}

$.writeln(na)
//returns an array of file names

 

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