Skip to main content
Participant
October 19, 2020
Question

Cant get recursive search to work

  • October 19, 2020
  • 3 replies
  • 193 views

Hello,

I need to do a recursive search and get all the files in all the directories from a root folder.I grabbed this adobe script from the forums.Unfortunately it doesnt work on line it gives me error 21: undefined not a object

if (f.name.slice(-4).toLowerCase() == ".jpg")

 so i narrowed it down to f.name is undefined i tried logging what type of variable it is using instanceof keyword but f isnt a Folder,File,or String type.Iam at a lost on were to go from here any help is appreciated thanks

function find_files (dir)
    {
    return find_files_sub (dir, []);
    }

function find_files_sub (dir, array)
    {
    var f = (dir).getFiles ();
    for (var i = 0; i < f.length; i++)
        {
        if (f instanceof Folder)
            find_files_sub (f, array);
        else
        {
          if(f instanceof Folder)
             fileOut.writeln("Is Folder")
          if(f instanceof File)
             fileOut.writeln("Is File")
          if(f instanceof String)
             fileOut.writeln("Is String")

            if (f.name.slice(-4).toLowerCase() == ".jpg")
                array.push (f);
          }
        }
    return array;
    }
This topic has been closed for replies.

3 replies

Legend
October 20, 2020
In the body of the loop, replace f everywhere with f[i].
If you took the code from a very old topic, then when transferring to this new forum all [i] disappeared (due to the crooked programmers of the site)
 
bhkz12Author
Participant
October 20, 2020

And this is why you dont trust anyone elses code for 10 years on adobe forums this code was posted as a correct answer,Indexers always help you go through each element of an a array good god.

bhkz12Author
Participant
October 20, 2020

Did a little more digging in the code it seems that variable f is of type object i dont know if i can cast f as a folder to test to see if its a file or folder,i though getFiles always return either Folder or File types.Atleast thats what it says in there reference pdf