var fs=require("fs"); var path=require("path") var filePath=path.resolve("E:\\KwDownload\\") fileDisplay(filePath) function fileDisplay(filePath) { fs.readdir(filePath,function(err,files){ console.log(files) if(err){ console.warn(err) }else { files.forEach(function (filename) { console.log(filename) //获取文件绝对路径 var fileDir=path.join(filePath,filename) fs.stat(fileDir,function (err,stats) { if(err){ console.warn("获取stat失败!"); }else { var isFile=stats.isFile(); var isDir=stats.isDirectory(); if(isFile){ console.log(fileDir) } if(isDir){ fileDisplay(fileDir) } } }) }) } }) }
node遍历文件
猜你喜欢
转载自blog.csdn.net/Mahuicool/article/details/86060598
今日推荐
周排行