zoukankan      html  css  js  c++  java
  • javascript 笔记

    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{//可选}

  • 相关阅读:
    JDK源码那些事儿之LinkedBlockingQueue
    JDK源码那些事儿之并发ConcurrentHashMap上篇
    JDK源码那些事儿之ArrayBlockingQueue
    JDK源码那些事儿之HashMap.TreeNode
    mycat使用schema配置
    redis连接数高居不下,怎么破?。。。。这么破
    修改tomcat使用的的编码方式
    centos6.x下让redis以服务方式运行
    mycatrule
    HTML和XML中的转义字符
  • 原文地址:https://www.cnblogs.com/go2anywhere/p/2748237.html
Copyright © 2011-2022 走看看