bat命令执行JS
.bat文件:
cscript WWW.js
.js文件:
function dellogfile(beforedays) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var dir = fso.GetFolder("E:\\IISLog\\En"); //改成你的 IIS 日志目录
//Enumerator用指针访问的项目集合:atEnd(),item(),moveFirst(),moveNext()
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);
JS执行BAT命令