一、JS创建客户端文件夹
var file;
var fso = new ActiveXObject("Scripting.FileSystemObject");
if(!fso.FolderExists("c:\\trace"))
{
fso.CreateFolder("c:\\trace");
}
二、JS创建客户端文件对象
var d=new Date();
var fname = "c:\\trace\\MyFile"+d.toLocaleDateString()+".txt";
if(fso.FileExists(fname)) {
file = fso.OpenTextFile(fname,8);
}else{
file = fso.CreateTextFile(fname);
}
知识拓展:完整的例子看下文。
function trace(orderNumber, msg){
var file;
var fso = new ActiveXObject("Scripting.FileSystemObject");
if(!fso.FolderExists("c:\\trace")) {
fso.CreateFolder("c:\\trace");
}
var d=new Date();
var fname = "c:\\trace\\MyFile"+d.toLocaleDateString()+".txt";
if(fso.FileExists(fname)) {
file = fso.OpenTextFile(fname,8);
}else{
file = fso.CreateTextFile(fname);
}
file.Write(orderNumber + "["+d.toLocaleTimeString()+"]"+msg+"\r\n");
file.Close();
}
</script>