fs-extra 获取指定路径的所有文件名称
可以使用fs-extra的readdirSync方法获取指定路径的所有文件名称。例如,以下代码可以获取当前文件夹下的所有文件名称:
const fs = require('fs-extra');
const path = require('path');
const directoryPath = path.join(__dirname);
const files = fs.readdirSync(directoryPath);
console.log(files);
输出结果可能类似于:
[ 'file1.txt', 'file2.js', 'folder1', 'folder2' ]
其中,'file1.txt'和'file2.js'是当前文件夹下的两个文件名称,'folder1'和'folder2'是当前文件夹下的两个文件夹名称。
原文地址: http://www.cveoy.top/t/topic/eDzv 著作权归作者所有。请勿转载和采集!