var fs = require(‘fs‘); var wenwa = function (pathname,callback) { fs.stat(pathname,function (err,data) { if(err) throw err; else { if(data.isDirectory()) { var wenheichouwa = function (callback){ fs.readdir(pathname,function (err,fileordir) { //console.log(fileordir); callback(fileordir) }); }; wenheichouwa(function (data) { for (var i=0;i<data.length;i++) { wenwa(pathname+"/"+data[i]) } }) } else { console.log(pathname) } } }); };
node.js之文件读写模块,配合递归函数遍历文件夹和其中的文件
原文:https://www.cnblogs.com/saintdingspage/p/11432870.html