当前位置:网站首页>Tool functions – get all files in the project folder
Tool functions – get all files in the project folder
2022-06-24 08:15:00 【Mr. Zirun】
about . The first hidden file will also be read .
'use strict';
const fs = require('fs');
const path = require('path');
const { promisify } = require('util');
const readdirPromise = promisify(fs.readdir);
const statPromise = promisify(fs.stat);
class File {
constructor(filename, size) {
this.filename = filename;
this.size = size;
}
}
function scanFs() {
const dir = process.cwd();
const result = [];
function collect(dir) {
const basedir = dir;
return readdirPromise(dir).then(files =>
Promise.all(files.map(fn => {
const fullpath = path.join(dir, fn);
const realpath = path.relative(basedir, fullpath);
return statPromise(fullpath).then(stats => {
if (stats.isDirectory()) {
return collect(fullpath);
}
const file = new File(realpath, stats.size)
result.push(file)
})
}))
)
}
return collect(dir).then(() => result);
}
module.exports = scanFs;边栏推荐
- Do you still have the opportunity to become a machine learning engineer without professional background?
- transformers PreTrainedTokenizer类
- Introduction to software engineering - Chapter 2 - feasibility study
- 2022 PMP project management examination agile knowledge points (1)
- 【点云数据集介绍】
- Decltype usage introduction
- For a detailed explanation of flex:1, flex:1
- 5g industrial router Gigabit high speed low delay
- 快速读论文----AD-GCL:Adversarial Graph Augmentation to Improve Graph Contrastive Learning
- [run the script framework in Django and store the data in the database]
猜你喜欢
随机推荐
Practice of opengauss database on CentOS, configuration
Unity culling related technologies
Swift 基礎 閉包/Block的使用(源碼)
Graphmae ---- quick reading of papers
Search and recommend those things
SVN实测常用操作-记录操作大全
Simple refraction effect
不止于观测|阿里云可观测套件正式发布
etcd备份恢复原理详解及踩坑实录
[ACNOI2022]做过也不会
自动化测试的未来趋势
FPGA的虚拟时钟如何使用?
软件工程导论——第三章——需求分析
For a detailed explanation of flex:1, flex:1
[teacher zhaoyuqiang] use the Oracle tracking file
os.path.join()使用过程中遇到的坑
[nilm] non intrusive load decomposition module nilmtk installation tutorial
[测试开发]初识软件测试
Graphmae - - lecture rapide des documents
对于flex:1的详细解释,flex:1








