1、判断本地文件是否存在
o.FileExists(文件路径),返回布尔类型。
var filePath = 'C:\\ test.txt'; var fso = new ActiveXObject("Scripting.FileSystemObject"); if(!fso.FileExists(filePath)){ alert('文件不存在'); }
2、获取本地文件创建时间和最后修改时间
file.DateCreated,file.DateLastModified。
var filePath = 'C:\\ test.txt'; var fso = new ActiveXObject("Scripting.FileSystemObject"); if(fso.FileExists(filePath)){ alert('文件不存在'); }
var f = fso.GetFile(filePath); var cdate= f.DateCreated; var mdate= f.DateLastModified;
具体使用创建时间还是最后修改时间要跟据具体情况而定。
3、时间比较
var filePath = 'C:\\ test.txt'; var fso = new ActiveXObject("Scripting.FileSystemObject"); if(fso.FileExists(filePath)){ alert('文件不存在'); }
var f = fso.GetFile(filePath); var mdate= f.DateLastModified;
var deadLineDate=new Date(Date.parse("2012-10-30 12:01:01".replace(/-/g,"/")));
if(mdate< deadLineDate){ alert('还有时间'); return false; }
时间.replace(/-/g,"/") 不能省略,否则在某些IE版本下会返回NaN.(好像是IE7)
4、执行文件
var filePath = 'C:\\ test.exe'; var wsh=new ActiveXObject("wscript.shell"); wsh.run(filePath)
5、异常处理
try{} catch(e){} finally{}
try{//必选
var filePath = 'C:\\ test.exe'; var wsh=new ActiveXObject("wscript.shell"); wsh.run(filePath)
}
catch(e){//必选
//alert(e.name);
//alert(e.message);
alert('请将本系统地址加到浏览器可信站点中,并保证以下位置为启用状态\n\r IE->工具->Internet选项->安全->可信站点->自定义级别->对未标记为可 安全执行脚本的ActiveX控件初始化并执行');
}
finally{//可选}
转载于:https://www.cnblogs.com/go2anywhere/archive/2012/10/31/2748237.html
相关资源:JavaScript基础笔记-尚硅谷视频自己总结