世界上最伟大的投资就是投资自己的教育
mike652638
id 8042
2 hours 3 minutes 50 seconds 弟子 大学生
-
貌似评论中 dirname 前面的两个短横下划线__被吞了 (没用到 markdown)
-
安利一个好用的 npm 库, 可以自动打开浏览器或文件
https://www.npmjs.com/package/open
npm i open 后使用简便:
const open = require('open');
(async () => {
await open(dirname + '/src/write.txt');
await open(dirname + '/favicon.ico');
await open('http://localhost:3000', {
app: 'firefox'
})
})() -
fs.rmdir() 删除非空目录 (目录下存在文件/子文件夹) 时会报错: Failed to delete the folder: Error: ENOTEMPTY: directory not empty ...
在 StackOverFlow(https://stackoverflow.com/questions/12627586/is-node-js-rmdir-recursive-will-it-work-on-non-empty-directories/12761924#12761924) 搜到的解决方案:
递归同步删除
deleteFolderRecursive = function(path) {
var files = [];
if( fs.existsSync(path) ) {
files = fs.readdirSync(path);
files.forEach(function(file,index){
var curPath = path + "/" + file;
if(fs.lstatSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
};
-
哈哈, 评论区老师回复的时候, 显示 XXX 对 XXX 回复 ..., 咋一看, 咋老师回复啥评论都用一个"对"字
© 汕尾市求知科技有限公司 | Rails365 Gitlab | Qiuzhi99 Gitlab | 知乎 | b 站 | 搜索
粤公网安备 44152102000088号 | 粤ICP备19038915号
Top