javascript - Adobe Air HTML recursive file walk to JSON -


i try create directory listing adobe air html. output should json document.

as template used node.js code: https://stackoverflow.com/a/11194896/799692

the file walk works. json object contain last folder.

<!doctype html> <html> <head>     <meta charset="utf-8">     <title>adobe air directory listening json</title>     <script type="text/javascript" src="airaliases.js"></script>  <!-- adobe air framework -->       <script type="text/javascript" src="jquery-2.0.3.min.js"></script> </head> <body>  <script type="text/javascript">  var completepath = air.file.applicationdirectory.resolvepath("data").nativepath;  window.onload = function() {         air.trace(json.stringify(dirtree(completepath), null, 4));  }    function dirtree(filename)  {      var currentfile = new air.file(filename);        var temp_path = currentfile.nativepath;                        info = {         path: temp_path,         name: currentfile.name     };      if (currentfile.isdirectory)     {            if (currentfile.name !="." && currentfile.name !="..")             {             info.type = "folder";             air.trace(object.size(info));             info.children = currentfile.getdirectorylisting().map(function(child) {                      return dirtree(child.nativepath);             });             }         }         else          {             info.type = "file";                   }        return info;                 } //end fn dirtree   // simple helper object size  object.size = function(obj) {     var size = 0, key;     (key in obj) {         if (obj.hasownproperty(key)) size++;     }     return size; };   </script> </body> </html> 

replace map anonymous function function pointer:

function select_child(child)    {    return dirtree(child.nativepath);   }  info.children = currentfile.getdirectorylisting().map(select_child); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -