DroidScript wiki

(was AndroidScript) unofficial documentation by the community

User Tools

Site Tools


sample_code:list_folders_and_subfolders

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

sample_code:list_folders_and_subfolders [2014/12/17 16:16] (current)
octazid created
Line 1: Line 1:
 +====== List all Folders and Subfolders ======
 +(Sample Code taken from the DroidScript Google-Group)
 +<code JavaScript Folders_and_Subfolders.js>​
 +//Called when application is started.
 +function OnStart()
 +{
 +  //Create a layout with objects vertically centered.
 +  lay = app.CreateLayout("​linear",​ "​VCenter,​FillXY"​);​
  
 +  //Create a list and add to layout.
 +  lst = app.CreateList("​Please Wait"​);​
 +  lay.AddChild(lst);​
 +  //Add layout to app.
 +  app.AddLayout(lay);​
 +
 +  app.ShowProgress("​Loading..."​);​
 +  lst.SetList(GetDirs("/​sdcard/​DroidScript",​ []).sort());​
 +  app.HideProgress();​
 +}
 +
 +//Check a directory for subdirectories.
 +function GetDirs(path,​ kidsfound)
 +{
 +  if (path != null && app.IsFolder(path))
 +  {
 +    kidsfound.push(path);​
 +    var children = app.ListFolder(path);​
 +    for (var i = 0; i < children.length;​ i++)
 +    {
 +      var fil = path + "/"​ + children[i];​
 +      if (app.IsFolder(fil))
 +      {
 +        kidsfound = GetDirs(fil,​ kidsfound);
 +      }
 +    }
 +  }
 +  return kidsfound;
 +}
 +</​code>​
sample_code/list_folders_and_subfolders.txt ยท Last modified: 2014/12/17 16:16 by octazid