Skip to main content
Loic.Aigon
Legend
October 27, 2009
Answered

[JS] Can I get Children Folders of a folder ?

  • October 27, 2009
  • 1 reply
  • 2679 views

Hi,

Meanwhile there is a Folder.getFiles() command, I didn't find any Folder.getFolders() or Folder.folders or Folder.children in the ESTK DOM.

The only way I see is to write this specific operation both in VB and AS and call them via a doScript depending on the system.

But before doing this, I would like to be sure JS couldn't help me.

Thanks for advices.

Loic

This topic has been closed for replies.
Correct answer Kasyan Servetsky

Hi Loic,

Here is how I solved this in my 'Place images script' — http://kasyan.ho.com.ua/place_images.html

// global variable (empty array)

var mySubFolders = [];

// myStartFolder is the folder from which to start collecting subfolders

mySubFolders = getSubFolders(myStartFolder);

function getSubFolders(theFolder) {

      var myFileList = theFolder.getFiles();

      for (var i = 0; i < myFileList.length; i++) {

            var myFile = myFileList;

            if (myFile instanceof Folder){

                  mySubFolders.push(myFile.absoluteURI);

                  getSubFolders(myFile);

            }

      }

      return mySubFolders;

}

Hope this helps.

Kasyan

1 reply

Kasyan Servetsky
Kasyan ServetskyCorrect answer
Legend
October 28, 2009

Hi Loic,

Here is how I solved this in my 'Place images script' — http://kasyan.ho.com.ua/place_images.html

// global variable (empty array)

var mySubFolders = [];

// myStartFolder is the folder from which to start collecting subfolders

mySubFolders = getSubFolders(myStartFolder);

function getSubFolders(theFolder) {

      var myFileList = theFolder.getFiles();

      for (var i = 0; i < myFileList.length; i++) {

            var myFile = myFileList;

            if (myFile instanceof Folder){

                  mySubFolders.push(myFile.absoluteURI);

                  getSubFolders(myFile);

            }

      }

      return mySubFolders;

}

Hope this helps.

Kasyan

Loic.Aigon
Legend
October 28, 2009

Hi Kasyan,

Thanks so much for your input.

It does work so well.You are a killer.

Regards,

Loic

Inspiring
October 28, 2009

The getFile function takes a mask parameter which can also be a function.

Thus you can filter the folders:

var f = Folder.selectDialog ("Which Folder?");

var sf = f.getFiles(onlyFolders);

var s = "";

for (var n = 0; n < sf.length; n++) {

  s += sf.name + "\r";

}

alert(s);

function onlyFolders(f) {

  if (f.constructor.name == "File") {

    return false;

  } else {

    return true;

  }