refactored
This commit is contained in:
parent
dad2e70092
commit
16f44f25fe
47
testSync.js
47
testSync.js
|
@ -2,39 +2,42 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var walk = require('./lib/walk')
|
var walk = require('./lib/walk')
|
||||||
, _ = require('underscore')
|
|
||||||
, fs = require('fs')
|
, fs = require('fs')
|
||||||
, sync = false
|
, options
|
||||||
, walker;
|
, walker
|
||||||
|
;
|
||||||
|
|
||||||
console.log(walk);
|
options = {
|
||||||
|
listeners: {
|
||||||
walker = walk.walk(".");
|
names: function (root, nodeNamesArray) {
|
||||||
|
nodeNamesArray.sort(function (a, b) {
|
||||||
walker.on("directory", function (root, dirStatsArray, next) {
|
if (a > b) return 1;
|
||||||
|
if (a < b) return -1;
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
, directories: function (root, dirStatsArray, next) {
|
||||||
// dirStatsArray is an array of `stat` objects with the additional attributes
|
// dirStatsArray is an array of `stat` objects with the additional attributes
|
||||||
// * type
|
// * type
|
||||||
// * error
|
// * error
|
||||||
// * name
|
// * name
|
||||||
//console.log(_.pluck(dirStatsArray, 'name'));
|
|
||||||
console.log(root + '/' + dirStatsArray.name);
|
|
||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
}
|
||||||
|
, file: function (root, fileStats, next) {
|
||||||
walker.on("file", function (root, fileStats, next) {
|
fs.readFile(fileStats.name, function () {
|
||||||
console.log(root + '/' + fileStats.name);
|
// doStuff
|
||||||
|
console.log(root, fileStats.name);
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
walker.on("errors", function (root, nodeStatsArray, next) {
|
, errors: function (root, nodeStatsArray, next) {
|
||||||
//console.log(nodeStatsArray);
|
|
||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
walker = walk.walkSync("/tmp", options);
|
||||||
|
|
||||||
walker.on("end", function () {
|
|
||||||
console.log("all done");
|
console.log("all done");
|
||||||
});
|
|
||||||
}());
|
}());
|
||||||
|
|
Loading…
Reference in New Issue