node 异步/同步文件删除

来源:互联网 发布:python write 换行 编辑:程序博客网 时间:2024/06/11 23:34
var fs = require("fs");//异步 文件删除(判断文件是否存在)fs.exists("./wen.txt", function(exist) {/* * exist 的值为布尔 * false 不存在 * true 存在 */console.log(exist);if(exist) {fs.unlink("./wen.txt", function(err) {if(err) {console.error();throw err;}console.log('文件删除成功');});}});//同步 文件删除(判断文件是否存在)if(fs.existsSync("./wen.txt")){fs.unlink("./wen.txt",function(err){if(err){console.error();throw err;}console.log('文件删除成功');});}else{console.log("文件不存在");}


原创粉丝点击