山猪的博客-贪吃狗咖喱 山猪的博客-贪吃狗咖喱
首页
  • 操作系统
  • 数据库
  • 其他运维笔记
  • Python
  • Java
  • 其他开发笔记
  • 技术文档
  • GitHub技巧
  • Apache NiFi
  • 博客搭建
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
  • 网站
  • 资源
  • Vue资源
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Shicong Zhou

ISTJ的IT男
首页
  • 操作系统
  • 数据库
  • 其他运维笔记
  • Python
  • Java
  • 其他开发笔记
  • 技术文档
  • GitHub技巧
  • Apache NiFi
  • 博客搭建
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
  • 网站
  • 资源
  • Vue资源
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 技术文档

  • GitHub技巧

  • Apache NiFi

  • Nodejs

    • nodejs递归读取所有文件
  • 博客搭建

  • 技术
  • Nodejs
xugaoyi
2019-12-26

nodejs递归读取所有文件

# nodejs递归读取所有文件


var fs = require('fs');
var path = require('path');
 
function readFileList(dir, filesList = []) {
    const files = fs.readdirSync(dir);
    console.log(files);
    files.forEach((item, index) => {
        var fullPath = path.join(dir, item);
        const stat = fs.statSync(fullPath);
        if (stat.isDirectory()) {      
            readFileList(path.join(dir, item), filesList);  //递归读取文件
        } else {                
            filesList.push(fullPath);                     
        }        
    });
    return filesList;
}
 
var filesList = [];
readFileList(__dirname,filesList);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
编辑 (opens new window)
上次更新: 2024/02/23, 06:03:27
Apache NiFi2.0 安装
vuepress-theme-vdoing在vercel中部署

← Apache NiFi2.0 安装 vuepress-theme-vdoing在vercel中部署→

最近更新
01
Linux时间设置
02-23
02
Ubuntu开机卡GRUB
02-22
03
Ubuntu NFS服务无法启动
02-22
更多文章>
Theme by Vdoing | Copyright © 2023-2024 Shicong Zhou | 浙ICP备2023040288号-1 | 浙ICP备2023040288号 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式