您目前尚未登陆,请选择【登陆】或【注册
首页->控件插件->javascript写的windows资源管理器>>scripts/javscript.js>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:javascript写的windows资源管理器
当前文件:文件类型 JSResourceManager/scripts/javscript.js打开代码结构图
普通视图
		            
1/************************************ 2descript:windows任务管理器---js文件 3author:姜南 4date:2008-3 5首发于www.51aspx.com(51aspx.com) 6*************************************/ 7 8//文件系统对象 9var fso=new ActiveXObject("Scripting.FileSystemObject"); 10var wsh=new ActiveXObject("WScript.Shell"); 11var Path=""; 12//获取所有磁盘信息 13 14function ShowFileInfo() 15{ 16 var s, n, e, x; 17 e = new Enumerator(fso.Drives); 18 for (; !e.atEnd(); e.moveNext()) 19 { 20 x = e.item(); 21 //驱动器号. 22 s=""; 23 s = s + x.DriveLetter; 24 //驱动器类型. 25 switch(x.DriveType) 26 { 27 case 0: n = "[未知驱动器]"; 28 break; 29 case 1: n = "[移动驱动器]"; 30 break; 31 case 2: n = "[本地硬盘]"; 32 break; 33 case 3: n = "[网络硬盘]"; 34 break; 35 case 4: n = "[CD-ROM]"; 36 break; 37 case 5: n = "[随机存储器]"; 38 break; 39 } 40 var li=document.createElement("li"); 41 var a=document.createElement("a"); 42 43 a.setAttribute("title","查看详细"); 44 a.setAttribute("href","#"); 45 46 a.onclick=function() 47 { 48 openDriv(this); 49 } 50 //驱动器卷标. 51 var driveMark=document.createTextNode(s); 52 a.appendChild(driveMark); 53 //驱动器类型. 54 var driveType=document.createTextNode(" "+n); 55 //驱动器总大小. 56 var totalSize=""; 57 var dirFreeSpace=""; 58 if(x.IsReady) 59 { 60 var tol=new Array(); 61 tol=ShowTotalSize(x).split(','); 62 totalSize="总共 "+tol[0]+" MB "; 63 dirFreeSpace="剩余 "+tol[1]+" MB "; 64 }else{ 65 totalSize="设备未就绪,无法计算空间大小。"; 66 } 67 var driveTotalSize=document.createTextNode(totalSize); 68 var driveFreeSpace=document.createTextNode(dirFreeSpace); 69 70 li.appendChild(a); 71 li.appendChild(driveType); 72 li.appendChild(driveTotalSize); 73 li.appendChild(driveFreeSpace); 74 if(x.IsReady) 75 { 76 var tol=new Array(); 77 tol=ShowTotalSize(x).split(','); 78 ShowFreePic(li,tol[0],tol[1]); 79 } 80 document.getElementById("uTitle").appendChild(li); 81 } 82} 83//获取提供路径下的文件夹或文件. 84function openDriv(linka) 85{ 86 var pathValue=""; 87 if(typeof(linka)=='object') 88 { 89 pathValue=linka.firstChild.nodeValue; 90 }else 91 { 92 pathValue=linka; 93 } 94 ChangePath(pathValue); 95 RemoveChild(document.getElementById("uSub")); 96 var subFile=document.getElementById("uSub"); 97 //获取文件夹. 98 var folders=ShowFolder(GetFormatPath(pathValue)); 99 //获取文件. 100 var files=ShowFolderFileList(GetFormatPath(pathValue)); 101 102 var filesList=new Array(); 103 var foldersList=new Array(); 104 filesList=files.split(','); 105 106 foldersList=folders.split(','); 107 108 for(var i=0;i<foldersList.length-1;i++) 109 { 110 var li=document.createElement("li"); 111 var fileNameA=document.createElement("a"); 112 var fileNameA1=document.createElement("a"); 113 114 var text=document.createTextNode("查看详细"); 115 var fileNameT=document.createTextNode(foldersList[i].toString()); 116 117 fileNameA.setAttribute("title","查看 "+foldersList[i].toString()+" 文件夹的内容。"); 118 fileNameA.setAttribute("href","#"); 119 fileNameA.onclick=function() 120 { 121 openDriv(this); 122 } 123 124 fileNameA1.setAttribute("title","单击查看文件夹详情。"); 125 fileNameA1.setAttribute("href","#"); 126 fileNameA1.setAttribute("className","view"); 127 fileNameA1.onclick=function() 128 { 129 Path=this.previousSibling.firstChild.nodeValue; 130 window.showModalDialog('view.html',window,"dialogWidth=600px;dialogHeight=400px;help=no;center=yes;"); 131 } 132 133 var filePic=document.createElement("img"); 134 filePic.setAttribute("src","images/folder.gif"); 135 filePic.setAttribute("title","文件夹"); 136 137 fileNameA1.appendChild(text); 138 fileNameA.appendChild(fileNameT); 139 li.appendChild(filePic); 140 li.appendChild(fileNameA); 141 li.appendChild(fileNameA1); 142 subFile.appendChild(li); 143 144 } 145 for(var i=0;i<filesList.length-1;i++) 146 { 147 var li=document.createElement("li"); 148 var fileA=document.createElement("a"); 149 var fileNameA1=document.createElement("a"); 150 var fileName=document.createTextNode(filesList[i].toString()); 151 var text=document.createTextNode("查看详细"); 152 fileA.setAttribute("href","#"); 153 fileA.appendChild(fileName); 154 fileA.onclick=function() 155 { 156 openFile(this); 157 } 158 159 fileNameA1.setAttribute("title","单击查看文件详情。"); 160 fileNameA1.setAttribute("href","#"); 161 fileNameA1.setAttribute("className","view"); 162 fileNameA1.onclick=function() 163 { 164 Path=this.previousSibling.firstChild.nodeValue; 165 window.showModalDialog('view.html',window,"dialogWidth=600px;dialogHeight=400px;help=no;center=yes;"); 166 } 167 var filePic=document.createElement("img"); 168 filePic.setAttribute("src","images/files.gif"); 169 filePic.setAttribute("title","文件"); 170 fileNameA1.appendChild(text); 171 172 li.appendChild(filePic); 173 li.appendChild(fileA); 174 li.appendChild(fileNameA1); 175 subFile.appendChild(li); 176 } 177 return false; 178} 179function openFile(file) 180{ 181 var openFilePath=file.firstChild.nodeValue; 182 try 183 { 184 wsh.Run(openFilePath); 185 } 186 catch(e) 187 { 188 alert("未找到与之相关的打开方式,或文件名当中包含空格。"); 189 } 190} 191function ShowTotalSize(drvPath) 192{ 193 var s; 194 s = Math.round(drvPath.TotalSize/1024/1024)+","; 195 s+= Math.round(drvPath.FreeSpace/1024/1024); 196 return(s); 197} 198function ShowFreePic(node,sumSize,residualSize) 199{ 200 var rate=parseInt(residualSize/sumSize*100); 201 var rates=parseInt(264*(residualSize/sumSize)); 202 var pivdiv=document.createElement("div"); 203 var pic1=document.createElement("img"); 204 var pic2=document.createElement("img"); 205 pivdiv.setAttribute("id","showpic"); 206 207 pic1.setAttribute("src","images/no_a_1.gif"); 208 pic1.setAttribute("width",264-rates); 209 pic1.setAttribute("alt","空间已用量"); 210 pic2.setAttribute("src","images/no_a_3.gif"); 211 pic2.setAttribute("width",rates); 212 pic2.setAttribute("alt","空间剩余量"); 213 pivdiv.appendChild(pic1); 214 pivdiv.appendChild(pic2); 215 node.appendChild(pivdiv); 216} 217//返回格式化路径 218function GetFormatPath(path) 219{ 220 var newPath; 221 /* 222 获得文件夹下面的文件夹。 223 磁盘必须要有\号。*/ 224 if(path.length==1) 225 { 226 //磁盘下的文件夹。 227 newPath=path+"://"; 228 }else 229 { 230 //文件夹下的文件夹,获取文件夹下面的文件夹只能为这种形式 C://ABCD// 231 var newPath=path.substring(0,1); 232 var tempF=path.substring(3,path.length); 233 newPath+="://"+tempF+"//"; 234 } 235 return newPath; 236} 237//获得指定目录下的所有文件夹. 238function ShowFolder(folderspec) 239{ 240 var f,fc,s; 241 s=""; 242 f= fso.GetFolder(folderspec); 243 fc = new Enumerator(f.SubFolders); 244 for (; !fc.atEnd(); fc.moveNext()) 245 { 246 s+=fc.item(); 247 s+=","; 248 } 249 return s; 250} 251//获得指定目录下的所有文件. 252function ShowFolderFileList(folderspec) 253{ 254 var f, fc, s; 255 f = fso.GetFolder(folderspec); 256 fc = new Enumerator(f.files); 257 s = ""; 258 for (; !fc.atEnd(); fc.moveNext()) 259 { 260 s += fc.item(); 261 s += ","; 262 } 263 return(s); 264} 265//删除所有子节点。 266function RemoveChild(uSub) 267{ 268 var lis=uSub.getElementsByTagName("li"); 269 for(var i=0;i<lis.length;i++) 270 { 271 uSub.removeChild(lis[i--]); 272 } 273} 274//改变当前路径。 275function ChangePath(path) 276{ 277 var paths=document.getElementById("path"); 278 var pathCount=paths.getElementsByTagName("li"); 279 var length=pathCount.length; 280 if(path.length==1) 281 { 282 for(var i=0;i<pathCount.length;i++) 283 { 284 paths.removeChild(pathCount[i--]); 285 } 286 } 287 for(var i=0;i<pathCount.length;i++) 288 { 289 if(pathCount[i].firstChild.firstChild.nodeValue==path) 290 { 291 del(i,paths,pathCount); 292 } 293 } 294 var pathli=document.createElement("li"); 295 var patha=document.createElement("a"); 296 patha.setAttribute("href","#"); 297