Devrim Devrim - 1 year ago 85
Javascript Question

Retrieve all directories with file system api

Is there a way to count all directories within a folder with file system api without being stuck in an infinite loop!?

Can't figure out why or where the leak is but I eventually had to quit my app after it got to 50K - it never looked like reaching an end point. I am on OS X so is it counting all the hidden directories and files such as DS Store?

//path: my folder
app.workspace.getDirectory(path, {}, function(directory){
var reader = directory.createReader();
for(var i = 0; entries.length; i++) {
console.log('Directory: ', entries[i]);
else {
//don't need to know anything else...
}, error);

Answer Source

Your for loop is never checking i against entries.length when it iterates.

Modify for(var i = 0; entries.length; i++)
to for(var i = 0; i < entries.length; i++)

Additionally, I assume if(entries.isDirectory)
should be if(entries[i].isDirectory).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download