var fs = require("fs");
var lineReader = require('line-reader');
var async = require("async");
var readFile= require("./ 路径/ readFileDao");
function run(){
var path = 'E:/'; //设置读取文件路径
explorer(path);
}
run();
function explorer(path){
fs.readdir(path, function(err,files){ //读取路径下所有文件
if(err){
console.log("error:\n"+err);
return;
}else{
async.mapSeries(files, function(file, callback) { //将文件逐一循环出
var index = 0;
var id = "";
var title = "";
var content = "";
lineReader.eachLine(path+file, function(line, last) { //path+file请保证为文件路径+文件名 line为文件每行内容
index ++;
if (index == 1) {
id = id + line;
} else if (index == 2) {
title = title + line;
} else if (index >= 4) {
content = content + line;
}
if(last){ //判断如为最后一行执行
var orderThing = {};
orderThing.id = id;
orderThing.title = title;
orderThing.content = content;
readFile. readFile中的自定接口(orderThing, function(err, result){
if(err){
callback(err);
return;
}else{
callback(null);
return;
}
});
}
});
}, function(err) {
if(err){
console.info(err);
console.info('read data error');
return;
}else{
console.info('read data success');
return;
}
});
}
});
}
var lineReader = require('line-reader');
var async = require("async");
var readFile= require("./ 路径/ readFileDao");
function run(){
var path = 'E:/'; //设置读取文件路径
explorer(path);
}
run();
function explorer(path){
fs.readdir(path, function(err,files){ //读取路径下所有文件
if(err){
console.log("error:\n"+err);
return;
}else{
async.mapSeries(files, function(file, callback) { //将文件逐一循环出
var index = 0;
var id = "";
var title = "";
var content = "";
lineReader.eachLine(path+file, function(line, last) { //path+file请保证为文件路径+文件名 line为文件每行内容
index ++;
if (index == 1) {
id = id + line;
} else if (index == 2) {
title = title + line;
} else if (index >= 4) {
content = content + line;
}
if(last){ //判断如为最后一行执行
var orderThing = {};
orderThing.id = id;
orderThing.title = title;
orderThing.content = content;
readFile. readFile中的自定接口(orderThing, function(err, result){
if(err){
callback(err);
return;
}else{
callback(null);
return;
}
});
}
});
}, function(err) {
if(err){
console.info(err);
console.info('read data error');
return;
}else{
console.info('read data success');
return;
}
});
}
});
}