Skip to content
Advertisement

best way to get folder and file list in Javascript

I’m using node-webkit, and am trying to have a user select a folder, and I’ll return the directory structure of that folder and recursively get its children.

I’ve got this working fairly simply with this code (in an Angular Controller).

JavaScript

Taking a moderate sized folder with 22 child folders and about 4 levels deep, it is taking a few minutes to get the entire directory structure.

Is there something that I’m obviously doing wrong here? I can’t believe it takes that long, seeing as I’m using the built in Node fs methods. Or is there a way to get the entire contents of a directory without touching each and every file?

I’m going to want to be able to use an Angular filter on the file names all the way down the tree, and possibly on the contents too, so delaying processing the entire tree isn’t likely a solution that would work.

Advertisement

Answer

In my project I use this function for getting huge amount of files. It’s pretty fast (put require("fs") out to make it even faster):

JavaScript

usage is clear:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement