foreachasync.js/examples/node/foreach-fs-readdir.js

21 lines
423 B
JavaScript
Raw Normal View History

2014-01-22 20:37:28 +00:00
'use strict';
var fs = require('fs')
, path = require('path')
, dirpath = path.join(__dirname, 'testfiles')
;
fs.readdir(dirpath, function (err, nodes) {
nodes.forEach(function (node) {
var filepath = path.join(dirpath, node)
;
console.log(filepath);
fs.readFile(filepath, null, function (err, contents) {
console.log(node, contents.length);
});
});
console.log('All Done');
});