nodeJs-autoMerge

/**
 * Created by Administrator on 2016/1/16.
 */

var fs = require('fs');

var filedir='automay';
console.log(filedir);
fs.watch(filedir, function(ev, file){
    //只要一个文件变化,对文件夹下所有文件进行读取,然后合并

    console.log(ev + ' / ' + file);

    fs.readdir(filedir, function(err, dataList){

        var arr = [];
        console.log(dataList);

        dataList.forEach(function (f){
            if(f){

                var info = fs.statSync(filedir + '/' + f);
                console.log(info);
                if(info.mode == 33206){
                    console.log(info);
                    arr.push(filedir + '/' + f);
                }
            }
        });

        var content = "";
        arr.forEach(function (f){
            var c = fs.readFileSync( f );

            content += c.toString() + '\n';
        });

        fs.writeFile("autoMerge.html",content);

    });

})

 

posted @ 2016-01-16 11:36  mayufo  阅读(282)  评论(0编辑  收藏  举报