I am attempting to generate a directory listing using Adobe AIR HTML that outputs as a JSON Document.
For guidance, I referenced this node.js code snippet:
While the file walk function is functioning correctly, the resulting JSON object only contains the information for the last folder.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Adobe Air directory listening to 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 for object size
Object.size = function(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
</script>
</body>
</html>