JS写入日志

try
{
var WSShell = WScript.CreateObject("WScript.Shell");
var FileSys = WScript.CreateObject("Scripting.FileSystemObject");
var num = WScript.ScriptFullName.lastIndexOf("\");
// 获取当前路径
var strCurPath = WScript.ScriptFullName.substr(0,num);
if (FileSys.FolderExists(strCurPath))
{
var log_file = strCurPath + "\outdir\log.txt";
var log_obj;
var ForAppending = 8;
// 假如存在日志文件就打开,否则就创建
if(FileSys.FileExists(log_file))
log_obj = FileSys.OpenTextFile(log_file,ForAppending);
else
log_obj = FileSys.CreateTextFile(log_file,true);

// 获取当前时间
var d, strDate = "compile finish time: "; // 声明变量。
d = new Date(); // 创建 Date 对象。
strDate +=d.toLocaleString(); //获取日期与时间
log_obj.WriteLine(strDate); // 写入日志文件
}
}
catch(e)
{
WScript.Echo(e.description);
}

原文地址:https://www.cnblogs.com/0828-li/p/6126009.html