//第三题
var fs =require('fs')
var path=process.argv[2]
fs.readFile(path,function(err,data){
var lines=data.toString().split('
').length-1;
console.log(lines)
})
View Code
第5题
//new module program.js var mymodule=require('./myfile.js') var dir=process.argv[2] var filter=process.argv[3] mymodule(dir,filter,function(err,list){ if(err) return console.error("ddddddd") list.forEach(function(file) { console.log(file) }) })
//myfile.js var fs =require('fs') var path=require('path') module.exports=function(dir,fileter,callback) { fs.readdir(dir,function(err,list){ if(err) return callback(err) list=list.filter(function(file){ if(path.extname(file)=='.'+fileter) return file }) callback(null,list) }) }