utlis-hrx-3.1
v1.0.0
Published
<!-- * @Author: your name * @Date: 2021-02-28 17:28:25 * @LastEditTime: 2021-02-28 17:29:41 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: \utlis-hrx-3.1\README.md -->
Downloads
7
Readme
郝瑞欣的js文件
fs的作用
function toJson(dirName) {
//判断是否为文件
let stat = fs.statSync(dirName);
if (stat.isFile()) {
//是文件
return {
name: dirName,
isFile: true,
content: fs.readFileSync(dirName, 'utf8'),
ext: dirName.slice(dirName.lastIndexOf('.')),
}
} else {
//是文件夹
return {
name: dirName,
isFile: false,
children: fs.readdirSync(dirName).map(item => {
return toJson(dirName + '/' + item);
})
}
}
}
let data = toJson('1');
fs.writeFileSync('data.json', JSON.stringify(data));