-----057-FileSystemObject-文件夹.html-----
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta http-equiv="content-type" content="text/html; charset=utf-8"> 5 <title>标题</title> 6 </head> 7 <body> 8 <div id="div1" style="position:absolute; left:10px; top:0px;"></div> 9 <div id="div2" style="position:absolute; left:250px; top:0px;"></div> 10 <div id="div3" style="position:absolute; top:220px;"> 11 <table> 12 <caption><h3>以桌面为相对路径,然后:</h3></caption> 13 <tr> 14 <td><input id="input1" type="text"></td> 15 <td><button onclick="newFolder(get(‘input1‘).value)">创建文件夹</button></td> 16 </tr> 17 <tr> 18 <td><input id="input2" type="text"></td> 19 <td><button onclick="delFolder(get(‘input2‘).value)">删除文件夹</button></td> 20 </tr> 21 <tr> 22 <td><input id="input3" type="text" size="5">-> 23 <input id="input4" type="text" size="6"></td> 24 <td><button onclick="moveFolder(get(‘input3‘).value, get(‘input4‘).value)">移动文件夹</button></td> 25 </tr> 26 <tr> 27 <td><input id="input5" type="text" size="5">-> 28 <input id="input6" type="text" size="6"></td> 29 <td><button onclick="copyFolder(get(‘input5‘).value, get(‘input6‘).value)">复制文件夹</button></td> 30 </tr> 31 <tr> 32 <td><button onclick="get(‘lbl1‘).innerText=fso.getParentFolderName(‘C:/USERS/BUTTON/DESKTOP‘)">获取父文件夹</button></td> 33 <td id="lbl1"></td> 34 </tr> 35 <tr> 36 <td><button onclick="get(‘lbl2‘).innerText=fso.GetSpecialFolder(0)">获取Windows文件夹</button></td> 37 <td id="lbl2"></td> 38 </tr> 39 <tr> 40 <td><button onclick="get(‘lbl3‘).innerText=fso.GetSpecialFolder(1)">获取System文件夹</button></td> 41 <td id="lbl3"></td> 42 </tr> 43 <tr> 44 <td><button onclick="get(‘lbl4‘).innerText=fso.GetSpecialFolder(2)">获取TMP文件夹</button></td> 45 <td id="lbl4"></td> 46 </tr> 47 </table> 48 </div> 49 <script type="text/javascript"> 50 var fso = new ActiveXObject("Scripting.FileSystemObject"); 51 var folder = new Enumerator(new ActiveXObject("Scripting.FileSystemObject").getFolder("D:").SubFolders); 52 var s = "<h3>D:的子文件夹:</h3><ol>"; 53 for(; !folder.atEnd(); folder.moveNext()) 54 { 55 s += "<li>" + folder.item(); 56 } 57 document.getElementById("div1").innerHTML += s; 58 59 var file = new Enumerator(new ActiveXObject("Scripting.FileSystemObject").getFolder("D:\\").Files); 60 var s = "<h3>D:的文件:</h3><ol>"; 61 for(; !file.atEnd(); file.moveNext()) 62 { 63 s += "<li>" + file.item(); 64 } 65 document.getElementById("div2").innerHTML += s; 66 67 function get(el) 68 { 69 return document.getElementById(el); 70 } 71 72 function newFolder(name) 73 { 74 new ActiveXObject("scripting.FileSystemObject").CreateFolder("C:/USERS/BUTTON/DESKTOP/" + name); 75 } 76 function delFolder(name) 77 { 78 new ActiveXObject("scripting.FileSystemObject").DeleteFolder("C:/USERS/BUTTON/DESKTOP/" + name); 79 } 80 function moveFolder(from, to) 81 { 82 new ActiveXObject("scripting.FileSystemObject").MoveFolder("C:/USERS/BUTTON/DESKTOP/" + from, "C:/USERS/BUTTON/DESKTOP/" + to + "/");//移动文件夹from到to下 83 } 84 function copyFolder(from, to) 85 { 86 new ActiveXObject("scripting.FileSystemObject").CopyFolder("C:/USERS/BUTTON/DESKTOP/" + from, "C:/USERS/BUTTON/DESKTOP/" + to + "/");//移动文件夹from到to下 87 } 88 </script> 89 </body> 90 </html>