X-Git-Url: http://git.pjr.cc/?p=nodejs-repoproxy.git;a=blobdiff_plain;f=unittests%2Frecurse.js;fp=unittests%2Frecurse.js;h=5819c0a56a40cf2844a2e34dcb8596230e631df3;hp=0000000000000000000000000000000000000000;hb=85fcaedb62209c356da64b865f981d212ae593d4;hpb=04f3190a0bcc430af31917456a957ecc80eb160b diff --git a/unittests/recurse.js b/unittests/recurse.js new file mode 100644 index 0000000..5819c0a --- /dev/null +++ b/unittests/recurse.js @@ -0,0 +1,33 @@ +var fs = require("fs"); +var path = require("path"); + + +// comes from http://stackoverflow.com/questions/5827612/node-js-fs-readdir-recursive-directory-search +var walk = function(dir, done) { + var results = []; + + fs.readdir(dir, function(err, list) { + if (err) return done(err); + var i = 0; + (function next() { + var file = list[i++]; + if (!file) return done(null, results); + file = path.normalize(dir + "/" + file); + fs.stat(file, function(err, stat) { + if (stat && stat.isDirectory()) { + walk(file, function(err, res) { + results = results.concat(res); + next(); + }); + } else { + if(!file.match(/.*\.meta.*\.filesize/)) results.push(file); + next(); + } + }); + })(); + }); +}; + +walk("/tmp/cache/ubuntu", function(err, res) { + console.log("result: ", res); +}); \ No newline at end of file