硬盘浏览程序,保存成网页格式便可使用


Posted in Javascript onDecember 03, 2006

硬盘浏览程序,保存成网页格式便可使用,放到随意一个盘,不要放桌面就可以了

<html> 
<head> 
<script language="javascript" type="text/javascript"> 
var errorinf=new Error(); 
var fso,fdrive,ffolder,ffile; 
var getdata="",selfpath="",drvpath="",favpath=""; 
var drive=new Array(),favorite=new Array(); 
var currentdrive=""; 
var hidestate=false; 
var lastdrive="",lastfav=""; 
var ppath=new Error(),ppathcounter=0,favcounter=0; 
var openfromfav=0; 
function initdoc() 
{ 
try 
{ 
   var outstr="",counter=0,i=0,writestr=""; 
   fso=new ActiveXObject("Scripting.FileSystemObject"); 
   selfpath=fso.GetParentFolderName(location.pathname.replace(/\//,"")); 
   drvpath=selfpath+"\\drvinf.ini"; 
   /*Get the hard drives on the computer.*/ 
   if(!fso.FileExists(drvpath)) 
      { 
         fdrive=fso.Drives; 
         getdata=new Enumerator(fdrive); 
         for(;!getdata.atEnd();getdata.moveNext()) 
           if(getdata.item().DriveType==2) 
             { 
                drive[counter]=getdata.item().DriveLetter; 
                writestr+=drive[counter]+"$"; 
                counter++; 
              } 
         ffile=fso.CreateTextFile(drvpath,true); 
         writestr=writestr.replace(/\$$/,""); 
         ffile.WriteLine(writestr+"\r"); 
         ffile.Close(); 
      } 
   else 
      { 
        ffile=fso.OpenTextFile(drvpath,1); 
        getdata=ffile.ReadAll().replace(/\'|\"|\\|\/|\:|\s+/g,""); 
        getdata=getdata.replace(/^\$+|\$+$/,""); 
        getdata=getdata.replace(/\$\$+/,"$"); 
        drive=getdata.split("$"); 
        ffile.Close(); 
      } 
   for(i=0;i<drive.length;i++) 
      outstr+="[<a href='' id='drive"+drive[i]+"' onClick=\"driveactive(drive["+i+"]);return false;\">本地磁盘:"+drive[i]+"</a>]"; 
   outstr+="显示隐藏内容<input style='height:15px;border:none;' type='checkbox' id='showorhide' onClick='hidestate=this.checked;flashdrive();'>" 
   document.getElementById("drives").innerHTML=outstr; 
   getdata="";outstr=""; 
   /*Get the exist item.*/ 
   favpath=selfpath+"\\favinf.ini"; 
   if(fso.FileExists(favpath)) 
    { 
      ffile=fso.OpenTextFile(favpath,1); 
      if(!ffile.AtEndOfStream) 
       { 
          getdata=ffile.ReadAll().replace(/\"|\s+/g,""); 
          getdata=getdata.replace(/^\|+|\|+$/,""); 
          getdata=getdata.replace(/\|\|+/,"|"); 
          favorite=getdata.split("|"); 
       } 
      ffile.Close(); 
      if(favorite[0]=="") 
        favcounter=0; 
      else 
        favcounter=favorite.length; 
    } 
   else 
    { 
      ffile=fso.CreateTextFile(favpath,true); 
      ffile.Close(); 
      favcounter=0; 
    }   
   openfav(); 
   driveactive("C"); 
   getdata=""; 
}catch(errorinf){alert(errorinf.description+"\n\n请不要随便改变数据文件*.ini文件中的内容.");} 
} 
function driveactive(driveval) 
{ 
try{   
   if(lastdrive==("drive"+driveval)&¤tdrive.match(/^[a-z]\:\\$/i)) 
     { 
       document.getElementById("showorhide").focus(); 
       return false; 
     } 
   if(lastdrive=="")lastdrive="driveC"; 
   document.getElementById(lastdrive).style.backgroundColor="#CCCCCC"; 
   lastdrive="drive"+driveval; 
   document.getElementById(lastdrive).style.backgroundColor="#FFFFDD"; 
   var att="",drv,totalsize,freespace,usespace,outstr="",pathstr="",attribu=0,subfolfil="",fcount=0; 
   drv=fso.GetDrive(driveval); 
   totalsize=Math.round((drv.TotalSize/Math.pow(2,30))*100)/100; 
   freespace=Math.round((drv.FreeSpace/Math.pow(2,30))*100)/100; 
   usespace=Math.round((totalsize-freespace)*100)/100; 
   totalsize>1 ? totalsize+="GB":totalsize=totalsize*Math.pow(2,10)+"MB"; 
   freespace>1 ? freespace+="GB":freespace=freespace*Math.pow(2,10)+"MB"; 
   usespace>1 ? usespace+="GB":usespace=usespace*Math.pow(2,10)+"MB"; 
   att+="本地磁盘:"+driveval+"\n文件系统:"+drv.FileSystem+"\n磁盘大小:"+totalsize+"\n已用空间:"+usespace+"\n可用空间:"+freespace+"\n"; 
   outstr=""; 
   currentdrive=pathstr=driveval+":\\"; 
   ffolder=fso.GetFolder(pathstr+"\\").SubFolders; 
   getdata=new Enumerator(ffolder); 
   outstr="<div class='showcon'>文件夹:[<a href='' onclick=\"return unfurlorfold('folshow',this);\">隐藏</a>]<div id='folshow'>"; 
   ppathcounter=0; 
   for(;!getdata.atEnd();getdata.moveNext()) 
    { 
     attribu=getdata.item().Attributes; 
     if(hidestate||attribu==16||attribu==17||attribu==48||attribu==49) 
      { 
        fcount++; 
        ppath[ppathcounter]=driveval+":\\"+getdata.item().name; 
        outstr+="<div><a href='' onClick=\"folderactive(ppath["+ppathcounter+"]);" 
        outstr+="return false;\">"+getdata.item().Name+"</a></div>"; 
        ppathcounter++; 
      } 
    } 
   subfolfil="找到"+fcount+"个文件夹,"; 
   fcount=0; 
   ffile=fso.GetFolder(pathstr).Files; 
   getdata=new Enumerator(ffile); 
   outstr+="</div></div><div class='showcon'>文  件:[<a href='' onclick=\"return unfurlorfold('filshow',this);\">隐藏</a>]<div id='filshow'>"; 
   for(;!getdata.atEnd();getdata.moveNext()) 
    { 
     attribu=getdata.item().Attributes; 
     if(hidestate||attribu==0||attribu==1||attribu==32||attribu==33) 
      { 
        fcount++; 
        outstr+="<div><a href=\""+currentdrive+"\" target='_blank'>"+getdata.item().Name+"</a></div>"; 
      } 
    }  
   outstr+="</div></div>"; 
   subfolfil+=fcount+"个文件."; 
   document.getElementById("showcontent").innerHTML=outstr; 
   document.getElementById("currentdrive").innerText=currentdrive; 
   document.getElementById("showdriveatt").innerText=att; 
   att="文件夹名称:\n\n文件夹大小:\n创建时间:\n\n修改时间:\n\n访问时间:\n\n"; 
   document.getElementById("showfolderatt").innerText=att; 
   document.getElementById("subfolfil").innerText=subfolfil; 
   att="[<a href=\""+currentdrive+"\" target='_blank'>打开</a>]"; 
   att+="[<a href='' onclick=\"addfav();return false;\">收藏</a>]"; 
   document.getElementById("openfol").innerHTML=att; 
   document.getElementById("showorhide").focus(); 
   getdata=""; 
   }catch(errorinf){alert(errorinf.description+"\n\n请不要随便改变数据文件*.ini文件中的内容.");} 
} 
function folderactive(folderval) 
{ 
try 
{ 
   var att="",fol="",totalsize=0,sizesign=""; 
   openfolder(folderval); 
   if(!folderval.match(/^[a-z]\:\\$/i)) 
    { 
     fol=fso.GetFolder(folderval); 
     totalsize=fol.Size/Math.pow(2,30); 
     totalsize>1 ? sizesign="GB":(totalsize=totalsize*Math.pow(2,10),sizesign="MB"); 
     (totalsize<1 && sizesign=="MB") ? (totalsize=totalsize*Math.pow(2,10),sizesign="KB"):{} 
     totalsize=Math.round((totalsize)*100)/100+sizesign; 
     att+="文件夹名称:\n"+fol.Name+"\n文件夹大小:"+totalsize+"\n创建时间:\n"; 
     att+=fol.DateCreated+"\n修改时间:\n"+fol.DateLastModified+"\n访问时间:\n"+fol.DateLastAccessed; 
     document.getElementById("showfolderatt").innerText=att+"\n"; 
    } 
}catch(errorinf){alert(errorinf.description+"\n\n请不要随便改变数据文件*.ini文件中的内容.");} 
} 
function openfolder(currfolder) 
{ 
try 
{ 
   var sign=0,outstr="",attribu=0,subfolfil="",fcount=0; 
   if(currfolder==""){alert("没有选择文件夹.");return false;} 
   currentdrive=currfolder; 
   ffolder=fso.GetFolder(currfolder).SubFolders; 
   getdata=new Enumerator(ffolder); 
   outstr="<div class='showcon'>文件夹:[<a href='' onclick=\"return unfurlorfold('folshow',this);\">隐藏</a>]<div id='folshow'>"; 
   ppathcounter=0; 
   for(;!getdata.atEnd();getdata.moveNext()) 
    { 
     attribu=getdata.item().Attributes; 
     if(hidestate||attribu==16||attribu==17||attribu==48||attribu==49) 
      { 
        fcount++; 
        ppath[ppathcounter]=currfolder.replace(/\\+$/i,"")+"\\"+getdata.item().name; 
        outstr+="<div><a href='' onClick=\"folderactive(ppath["+ppathcounter+"]);" 
        outstr+="return false;\">"+getdata.item().Name+"</a></div>"; 
        ppathcounter++; 
      } 
    } 
   subfolfil="找到"+fcount+"个文件夹,"; 
   fcount=0; 
   ffile=fso.GetFolder(currfolder).Files; 
   getdata=new Enumerator(ffile); 
   outstr+="</div></div></div><div class='showcon'>文  件:[<a href='' onclick=\"return unfurlorfold('filshow',this);\">隐藏</a>]<div id='filshow'>"; 
   for(;!getdata.atEnd();getdata.moveNext()) 
    { 
     attribu=getdata.item().Attributes; 
     if(hidestate||attribu==0||attribu==1||attribu==32||attribu==33) 
      { 
        fcount++; 
        if(openfromfav==0) 
          outstr+="<div><a href=\""+currentdrive+"\" target='_blank'>"+getdata.item().Name+"</a></div>"; 
        else 
          outstr+="<div><a href=\""+currentdrive+"\\"+getdata.item().Name+"\" target='_blank'>"+getdata.item().Name+"</a></div>"; 
      } 
    }    
   outstr+="</div></div>";   
   subfolfil+=fcount+"个文件."; 
   document.getElementById("showcontent").innerHTML=outstr; 
   document.getElementById("currentdrive").innerText=currentdrive; 
   att="文件夹名称:\n\n文件夹大小:\n创建时间:\n\n修改时间:\n\n访问时间:"; 
   document.getElementById("showfolderatt").innerText=att; 
   document.getElementById("subfolfil").innerText=subfolfil; 
   att="[<a href=\""+currentdrive+"\" target='_blank'>打开</a>]"; 
   att+="[<a href='' onclick=\"addfav();return false;\">收藏</a>]"; 
   document.getElementById("openfol").innerHTML=att; 
   getdata=""; 
   openfromfav=0; 
  }catch(errorinf){alert(errorinf.description+"\n\n请不要随便改变数据文件*.ini文件中的内容.");} 
} 
function upfile() 
{ 
   var rootpath=""; 
   rootpath=currentdrive; 
   if(!rootpath.match(/^[a-z]\:\\$/i)) 
     { 
        rootpath=rootpath.replace(/\\[^\\]*$/,""); 
        if(rootpath.match(/^[a-z]\:$/i)){rootpath+="\\";} 
        folderactive(rootpath); 
     } 
   else 
     alert("驱动器根目录."); 
} 
function flashdrive() 
{ 
  folderactive(currentdrive); 
} 
function openfav() 
{ 
   lastfav=""; 
   var outstr="",i=0; 
   for(i;i<favcounter;i++) 
    { 
      outstr+="<a id='fav"+i+"' href='' onclick=\"openfromfav=1;folderactive(favorite["+i+"]);" 
      outstr+="favactive(this.id);return false;\" target='_blank'>"+favorite[i].replace(/^.+\\/,"")+"</a><br>"; 
    } 
   document.getElementById("showfavorite").innerHTML=outstr; 
   document.getElementById("delfav").value=""; 
} 
function favactive(favid) 
{ 
   var i=parseInt(favid.match(/\d/)); 
   if(lastfav!="") 
      document.getElementById(lastfav).style.backgroundColor="#CCCCCC"; 
   lastfav=favid; 
   document.getElementById("delfav").value=favorite[i]; 
   document.getElementById(lastfav).style.backgroundColor="#FFFFDD"; 
   document.getElementById("showorhide").focus(); 
} 
function addfav() 
{ 
try 
{ 
   if(currentdrive.match(/^[a-z]\:\\$/i)) 
     { 
       alert("只能收藏文件夹."); 
       return false; 
     } 
   var i=0; 
   for(i=0;i<favcounter;i++) 
     { 
       if(favorite[i]==currentdrive) 
         { 
            alert("常用文件夹中已经存在该文件夹."); 
            return false; 
         } 
     } 
   if(fso.FileExists(favpath)) 
     { 
       ffile=fso.OpenTextFile(favpath,8); 
     } 
   else 
     { 
       ffile=fso.CreateTextFile(favpath,true); 
     } 
   ffile.Write("|"+currentdrive); 
   ffile.Close(); 
   favorite[favcounter]=currentdrive; 
   favcounter++; 
   openfav(); 
   alert("添加成功."); 
}catch(errorinf){alert(errorinf.description+"\n\n请不要随便删除数据文件*.ini文件.");} 
} 
function delfav() 
{ 
try 
{ 
   var delpath=document.getElementById("delfav").value; 
   var i=lastfav.match(/\d/),j=parseInt(i); 
   var newfav=""; 
   document.getElementById("showorhide").focus(); 
   if(delpath=="") 
     { 
        alert("没有选择常用文件夹."); 
        return false; 
     } 
   if(confirm("确定删除常用文件夹(并非从硬盘删除):\n"+delpath+"\n?")) 
     { 
        favcounter--; 
        for(j;j<favcounter;j++) 
          favorite[j]=favorite[j+1]; 
        for(j=0;j<favcounter;j++) 
          newfav+=favorite[j]+"|"; 
        ffile=fso.OpenTextFile(favpath,2); 
        newfav=newfav.replace(/^\||\|$/,""); 
        ffile.WriteLine(newfav); 
        ffile.Close(); 
        openfav(); 
        document.getElementById("delfav").value=""; 
        alert("删除成功."); 
     } }catch(errorinf){document.getElementById("delfav").value="";alert(errorinf.description+"\n\n请不要随便删除数据文件*.ini文件.");} 
} 
function unfurlorfold(objid,obj) 
{ 
  if(obj.innerText=="隐藏") 
     { 
       obj.innerText="显示"; 
       document.getElementById(objid).style.display="none"; 
     } 
  else 
     { 
       obj.innerText="隐藏"; 
       document.getElementById(objid).style.display=""; 
     }   
  document.getElementById("showorhide").focus();  
  return false;   
} 
</script> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
<title>FileLookThroughAdmin V1.0</title> 
<style type="text/css"> 
<!-- 
body{ 
background-color:#EEEEEE;} 
div.main{ 
background-color:#CCCCCC; 
width:100%; 
padding:6px 10px 10px;} 
h1{font-size:36px; 
font-family:"华文彩云"; 
color:#0000FF;} 
hr{ 
width:95%; 
text-align:left;} 
table.tableclass{ 
table-layout:fixed; 
word-wrap:break-word; 
width:100%; 
font-size:12px; 
background-color:#EEEEEE;} 
table.tableclass td{ 
background-color:#CCCCCC;} 
#drive{} 
td.drvinf{ 
vertical-align:top; 
padding:5px;} 
td.folderfile{ 
height:430px; 
vertical-align:top;} 
td.folderfile div.showcon{ 
width:100%;} 
td.folderfile div.showcon div div{ 
padding:1px 0px; 
width:49%; 
float:left;} 
a:link{text-decoration:none; 
color:#0000FF;} 
a:active{text-decoration:none; 
color:#0000FF;} 
a:visited{text-decoration:none; 
color:#0000FF;} 
a:hover{ 
text-decoration:underline; 
color:#FF0000; 
background-color:#FFFFDD;} 
.button{ 
border:none; 
height:20px; 
width:50px; 
background-color:#CCCCCC;} 
td.fav{ 
vertical-align:top; 
padding:5px;} 
--> 
</style> 
</head> 
<body onLoad="javascript:initdoc();status='FileLookThroughAdmin V1.0';"> 
<div class="main"> 
  <h1>FileLookThroughAdmin</h1> 
  <div style="margin-top:-36px;"><hr></div> 
  <div style="margin-top:-14px;position:relative;left:5%;"><hr></div> 
  <div> 
    <table class="tableclass"> 
      <tr align="center"> 
        <td width="18%">收藏夹</td> 
        <td width="60%">文件夹及文件</td> 
        <td>相关信息</td> 
      </tr> 
      <tr> 
        <td align="center"> 
          HardDrives>> 
        </td> 
        <td colspan="2"> 
          <div id="drives"></div> 
        </td> 
      </tr> 
      <tr> 
        <td align="center"> 
          Tag>> 
        </td> 
        <td align="center" colspan="2"> 
          DisplayContent 
        </td> 
      </tr> 
      <tr> 
        <td align="center"> 
          CurrentPath>> 
        </td> 
        <td colspan="2"> 
          <div id="currentdrive"></div> 
        </td> 
      </tr> 
      <tr> 
        <td class="fav"> 
          <div>常用文件夹:</div> 
          <div id="showfavorite"></div> 
        </td> 
        <td rowspan="2" class="folderfile"> 
          <div onclick="upfile();" style="height:15px;cursor:pointer;padding-top:5px;" align="center" 
           onmouseover="this.style.backgroundColor='#FFFFDD';" 
           onmouseout="this.style.backgroundColor='#CCCCCC';"> 
          上一级目录</div> 
          <div id="showcontent" style="padding-left:5px;"></div> 
        </td> 
        <td rowspan="2" class="drvinf"> 
          <font color="#FF0000">当前驱动器信息:</font> 
          <div id="showdriveatt"></div> 
          <font color="#FF0000">当前文件夹信息:</font> 
          <span id="openfol"></span> 
          <div id="showfolderatt"></div> 
          <div id="subfolfil" style="color:#FF0000;"></div> 
        </td> 
      </tr> 
      <tr> 
        <td class="fav"> 
          <div>删除常用文件夹:</div><br> 
          <div align="center"> 
            P:<input id="delfav" type="text" style="border:none;" readonly><br><br> 
            [<a href="" onClick="delfav();return false;">执行删除</a>] 
          </div> 
        </td> 
      </tr> 
    </table> 
  </div> 
</div> 
<div> 
  <font style="font-size:12px;cursor:default;" color="#666666" onmouseover="this.color='#FF0000'" onmouseout="this.color='#666666'"> 
    Design:sgw.LKing(∮LKing♂)[FS:Ecjtu2006|QQ:28857496|E-Mail:sgw.lking@gmail.com][@06.11] 
  </font> 
</div> 
</body> 
</html>
Javascript 相关文章推荐
使用正则替换变量
May 05 Javascript
用jQuery扩展自写的 UI导航
Jan 13 Javascript
JSON 教程 json入门学习笔记
Sep 22 Javascript
javascript开发随笔二 动态加载js和文件
Nov 25 Javascript
利用js判断浏览器类型(是否为IE,Firefox,Opera浏览器)
Nov 22 Javascript
Node.js开源应用框架HapiJS介绍
Jan 14 Javascript
非常棒的jQuery图片轮播效果
Apr 17 Javascript
省市联动效果的简单实现代码(推荐)
Jun 06 Javascript
解决Vue2.x父组件与子组件之间的双向绑定问题
Mar 06 Javascript
Vue-cropper 图片裁剪的基本原理及思路讲解
Apr 17 Javascript
Angular angular-file-upload文件上传的示例代码
Aug 23 Javascript
使用Javascript简单计算器
Nov 17 Javascript
常用js脚本
Dec 03 #Javascript
论坛特效代码收集(落伍转发-不错)
Dec 02 #Javascript
线路分流自动跳转代码;希望对大家有用!
Dec 02 #Javascript
phpwind放自动注册方法
Dec 02 #Javascript
一段好玩的JavaScript代码
Dec 01 #Javascript
[原创]网络复制内容时常用的正则+editplus
Nov 30 #Javascript
JavaScript中令你抓狂的魔术变量
Nov 30 #Javascript
You might like
php数组函数序列之end() - 移动数组内部指针到最后一个元素,并返回该元素的值
2011/10/31 PHP
smarty模板引擎使用内建函数foreach循环取出所有数组值的方法
2015/01/22 PHP
PHP编程获取图片的主色调的方法【基于Imagick扩展】
2017/08/02 PHP
JavaScript isArray()函数判断对象类型的种种方法
2010/10/11 Javascript
Jquery 表格合并的问题分享
2011/09/17 Javascript
jQuery弹出层始终垂直居中相对于屏幕或当前窗口
2013/04/01 Javascript
使用JS实现jQuery的addClass, removeClass, hasClass函数功能
2014/10/31 Javascript
一种新的javascript对象创建方式Object.create()
2015/12/28 Javascript
jQuery实现邮箱下拉列表自动补全功能
2016/09/08 Javascript
Bootstrap Table使用方法解析
2016/10/19 Javascript
jQuery中值得注意的trigger方法浅析
2016/12/12 Javascript
基于Vue如何封装分页组件
2016/12/16 Javascript
基于JavaScript实现本地图片预览
2017/02/08 Javascript
浅谈键盘上回车按钮的js触发事件
2017/02/13 Javascript
jquery获取transform里的值实现方法
2017/12/12 jQuery
微信小程序获取音频时长与实时获取播放进度问题
2018/08/28 Javascript
vue自定义tap指令及tap事件的实现
2018/09/18 Javascript
微信小程序实现日历效果
2018/12/28 Javascript
JS实现倒序输出的几种常用方法示例
2019/04/13 Javascript
js通过canvas生成图片缩略图
2020/10/02 Javascript
[01:59]游戏“zheng”当时试玩会
2019/08/21 DOTA
Python中线程的MQ消息队列实现以及消息队列的优点解析
2016/06/29 Python
python解析基于xml格式的日志文件
2017/02/25 Python
python入门教程之识别验证码
2017/03/04 Python
Python常用内置模块之xml模块(详解)
2017/05/23 Python
python re模块findall()函数实例解析
2018/01/19 Python
python django下载大的csv文件实现方法分析
2019/07/19 Python
详解用python计算阶乘的几种方法
2019/08/14 Python
django中使用事务及接入支付宝支付功能
2019/09/15 Python
python基于FTP实现文件传输相关功能代码实例
2019/09/28 Python
细说CSS3中box属性中的overflow-x属性和overflow-y属性值的效果
2014/07/21 HTML / CSS
HTML5+CSS3实现无插件拖拽上传图片(支持预览与批量)
2017/01/05 HTML / CSS
canvas如何实现多张图片编辑的图片编辑器
2020/03/10 HTML / CSS
行政助理的职责
2013/11/14 职场文书
外语专业毕业生个人的自荐信
2013/11/19 职场文书
windows下快速安装nginx并配置开机自启动的方法
2021/05/11 Servers