nodejs获取文件夹下所有文件及文件信息(Sync)
2017/06/06 标签:
nodejs
'use strict';
const fs=require('fs');
const path=require('path');
//返回文件夹下所有文件信息
var getFiles=function(filePath){
var files=[];
var getFilesLoop=function(filePath){
var filesCurrent=fs.readdirSync(filePath);
for(let i=0;i<filesCurrent.length;i++){
var fileStatCurrent={};
fileStatCurrent.path=path.join(filePath,filesCurrent[i]);
try{
fileStatCurrent.stats=fs.statSync(fileStatCurrent.path);
files.push(fileStatCurrent);
if(fileStatCurrent.stats.isDirectory()){
getFilesLoop(fileStatCurrent.path);
}
}catch(e){
//console.log(e)
}
}
}
getFilesLoop(filePath);
return files;
}
console.log(getFiles(path.resolve('D:\\soft\\fet4\\node_modules\\._bin-build@2.2.0@bin-build')));
上一篇:
iconfont图标数字转文字解决方案
静水缘首页
文章分类
最新文章
- nodejs私钥加密公钥解密的一个例子
- uniapp和微信小程序判断程序运行在开发或者测试或者线上版本的方法分别是什么
- electron使用electron-builder打包后模块包含exe文件执行失败
- Compile is disallowed on the main thread, if the buffer size is larger than 4KB
- better-sqlite3简介及常用操作
- nodejs 操作数据库的库
- nodejs使用http-proxy库实现多个域名代理和同时代理websocket的例子,代理包含https和http两种协议
- iis配置反向代理
- javascript伪多线程代码
- ip所在地址段判断