我可以使用以下代码读取多个文件。如何在所有文件上运行相同的逻辑并将更新的文件写入另一个输出目录?
var fs = require('fs'),
async = require('async'),
readMultipleFiles = require('read-multiple-files');
var dirPath = 'Input_Folder/';
fs.readdir(dirPath, function (err, filesPath) {
if (err) throw err;
filesPath = filesPath.map(function (filePath) {
return dirPath + filePath;
});
async.map(filesPath, function (filePath, cb) {
fs.readFile(filePath, 'utf8', cb);
}, function (err, results) {
console.log(results);
});
});
fs.readdir(dirPath, function (err, filesPath) {
if (err) throw err;
filesPath = filesPath.map(function (filePath) {
return dirPath + filePath;
});
readMultipleFiles(filesPath, 'utf8', function (err, results) {
if (err)
throw err;
console.log(results);
});
});