node.js - 如何使用 nodejs/expressjs 删除目录中超过 6 个月的文件?
问题描述
这里我不是在谈论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
and withunlink
但因为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, m, d, h, mi, 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
推荐阅读
- python - 将字符串视为列表
- android-studio - 无法解析 Android Studio 上的原始符号错误
- html - PNG图像不显示透明
- rxjs - 保证发射之间的“n”秒,而无需最初等待
- c++ - cmake完成生成文件后如何自动制作
- wordpress - 在 functions.php 中使用 Composer 类
- android - 在编辑文本中按零任意次,但用户应该只能看到 1 位数字,例如计算器
- javascript - 如何正确使用 innerHTML 更改文本字段中的文本
- facebook-graph-api - Facebook 图形 api 发布状态
- mongodb - mongo-go-driver 投影数组长度