问题描述
这里我不是在谈论 temp
文件目录。
是关于我的项目。
这是以下 structure
我试图从每个登录我网站的用户的目录中关注到 delete the files
:
- 用户在
automatic email alert
之前收到nodemailer
(我使用的是one week of 6 months finish
)作为通知,文件将在a week
之后被删除,因此他可以采取如果他愿意,可以备份。 - 第二个
automatic email alert
(我正在使用nodemailer
),就在one day of 6 months finish
之前,明天文件将被删除。 - 最后一天,(在总共
6 months
之后)文件将被自动成功删除。
我尝试的代码是使用 setTimeout
和 unlink
但由于 max time
的 setTimeout
我们可以放的是 approx 24 days
而不是更多
那么有什么可能的方法来做到这一点?
解决方法
var y,m,d,h,mi,da = new Date();
y = da.getFullYear();
da.setMonth(da.getMonth() + 5);
m = da.getMonth();
d = da.getDate();
h = da.getHours();
mi = da.getMinutes();
console.log("month = " + m);
var date = new Date(y,0);
console.log(date);
var j = schedule.scheduleJob(date,function(){
fs.unlink(___path,function(err,success){
if(err)
{
console.log(err);
return res.end('{"msg" : "Unable to unlink the Bigpaths4Clients files : Rejected","status" : 700}');
}
else {
User.updateMany({"Addtasks.commonID":req.query.commonIDs},{$set: {"Addtasks.$.background" :'linear-gradient(45deg,#D70652,#FF025E)',"Addtasks.$.status" :'Deleted'}},function (error,success) {
if (error) {
console.log("error = "+ error );
}
else {
console.log('file deleted successfully and status set as Deleted');
}
})
}
})
}); //scheduler closed