posts - 32, comments - 59, trackbacks - 0, articles - 2
  IT博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

JavaScript显示驱动器信息

Posted on 2005-08-07 09:01 这里的黄昏静悄悄 阅读(277) 评论(0)  编辑 收藏 引用 所属分类: SDKLife
摘要:       JavaScript(这里指在浏览器中运行的JavaScript而非直接运行的JS)利用ActiveXObject控件可以操作机器上的文件。这里说一下显示驱动器信息的方法。

关键字:Drives集合、JavaScript

       利用JavaScript显示驱动器信息主要利用Drives集合,该集合包括驱动器的一般信息,如驱动器类型、容量、可用容量等等!但是首先我们应该建立ActiveXObject的FSO对象。方法如下
       var fso = new ActiveXObject("Scripting.FileSystemObject");
这样我们就能用FileSystemObject了。
    var DriveSet = new Enumerator (fso.Drives);
    var DriveInfo, DriveItem;
    for(; !DriveSet.atEnd(); DriveSet.moveNext())
    {
        DriveItem = DriveInfo.item();
        //下面就可以显示letter/totalsize/freespace/drivetype/serialnumber等信息了。
        if(DriveItem.IsReady) // IsReady?
          {
              switch(DriveItem.DriveType) 
               {
                  case 1: break;//floppy drive
                  case 2: break;//fixed drive
                  // other types
               }
               // Math.round(DriveItem.TotalSize/1024/1024/1024*100)/100   保留2位小数GB
               // DriveItem.FreeSpace
               // DriveItem.ShareName
               // DriveItem.SerialNumber
               // DriveItem.SystemType
               //...
          } 
    }

具体用法可以自己试试
只有注册用户登录后才能发表评论。