I was trying to get a listing of files in a directory and send the output 
to clients using socket.io. First I tried with readdir which works good and 
pretty fast but is not able to sort the files by modified date (or atleast 
I wasnt able to find out how). 

 fs.readdir(logDrivesPath.replace(/#/,drive), function(err, files){
                        console.log(files);
                        socket.emit('filesList', files);
});

so i then used child process ls to get the listing in correct sorting order

var ls = exec('ls -t ' + logDrivesPath.replace(/#/,drive) + ' | xargs -n1 
basename',
                        function(err, stdout, stderr){
                                console.log("ls exec completed");
                                if(err == null){
                                        socket.emit('filesList', 
stdout.toString('utf8').split('\n'));
                                }
                                else{
                                        console.log(stderr);
                                        console.log(err);
                                }
                        });

the second option works fine but its much slower than the readdir option. 
It almost takes 3-4 seconds to get the listing while readdir returns the 
same list in less than a second so there is a significant difference. I was 
wondering if there is a way to use readdir but get the files sorted 
properly and secondly why is the childprocess option so much slower than 
readdir.

Thanks
Adeel

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to