运行逻辑并将所有更新的文件写入另一个输出目录

时间:2019-07-16 23:10:39

标签: javascript node.js node-modules

我可以使用以下代码读取多个文件。如何在所有文件上运行相同的逻辑并将更新的文件写入另一个输出目录?

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);
    });
});

0 个答案:

没有答案
相关问题