Permalink
Browse files

first try

  • Loading branch information...
0 parents commit ed7e2ef6c261f9d929d9a0caaf624c3b49a9b87f @refractalize committed Feb 24, 2011
Showing with 30 additions and 0 deletions.
  1. +30 −0 lsdir.js
@@ -0,0 +1,30 @@
+var fs = require('fs');
+var _ = require('underscore');
+
+var getDirectories = function (receiveDirectories) {
+ var dirs = [];
+ var n = 0;
+
+ fs.readdir('.', function (err, files) {
+ _(files).each(function (file) {
+ n++;
+ fs.stat(file, function (err, fileStat) {
+ if (fileStat.isDirectory()) {
+ dirs.push(file);
+ }
+ n--;
+ if (n==0) {
+ receiveDirectories(dirs);
+ }
+ });
+ });
+ });
+
+ receiveDirectories(dirs);
+}
+
+getDirectories(function (dirs) {
+ _(dirs).each(function (dir) {
+ console.log(dir);
+ });
+});

0 comments on commit ed7e2ef

Please sign in to comment.