ana*_*ana 1 path fs node.js express
我想根据数据创建文件。如果文件存在今天的日期,那么它一定不能创建文件。我已经写了一些代码
path.exists('./LOG/BAlDate-Info' +Date()+'.txt', function(exists) {
if (!exists) {
fs.writeFile('./LOG/BALDate-Info' +Date()+'.txt',"BAl-Employee is called @ "+ Date(),function(err){
if(err){
console.log("error is: " + err)
}
else
console.log("no error found");
});
}
});
Run Code Online (Sandbox Code Playgroud)
在这种情况下,每次我运行此代码时,它都会创建文件,但我只想创建今天的单个文件。在这种情况下请帮帮我
小智 6
一种选择是像这样命名您的日志文件:
var now = new Date();
var logfile_name = './LOG/BALDate-Info-' + now.getFullYear() + "-"+ now.getMonth() + "-" + now.getDate() +'.txt'
Run Code Online (Sandbox Code Playgroud)
您的文件应类似于'./LOG/BALDate-Info-2018-4-12.txt'
| 归档时间: |
|
| 查看次数: |
3594 次 |
| 最近记录: |