把保存成deliislog.js然后拖到计划任务里就行了
function dellogfile(beforedays) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var dir = fso.GetFolder("C:\\WINDOWS\\system32\\LogFiles"); //改成你的 IIS 日志目录
for (var fc = new Enumerator(dir.SubFolders); !fc.atEnd(); fc.moveNext()) {
if (fc.item().name.substr(0,5) == "W3SVC") {
for (var logfiles = new Enumerator(fc.item().Files); !logfiles.atEnd();
logfiles.moveNext()) {
var fileName = logfiles.item().name;
var year = "20" + fileName.substr(2, 2);
var mouth = fileName.substr(4, 2);
var day = fileName.substr(6, 2);
var days = Math.round(((new Date()).getTime() - Date.UTC(year, mouth - 1, day)) /
1000 / 60 / 60 / 24);
if (days >= beforedays) logfiles.item().Delete();
}
}
}
}
dellogfile(60); //保留多少天的IIS日志