...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript"> function init(){ var fso = new ActiveXObject("Scripting.FileSystemObject"); // 獲取文件相關信息 var f1 = fso.GetFile("F:\\test\\test.txt"); alert('文件上次修改日期:' + f1.DateLastModified); var drv; var s = ''; // 獲取磁碟相關信息 drv = fso.GetDrive(fso.GetDriveName("C:\\")); s += 'Drive C:' + '-' + drv.VolumeName + '\n'; s += 'Total Space:' + drv.TotalSize / 1024 + 'Kb' + '\n'; s += 'Free Space:' + drv.FreeSpace / 1024 + 'Kb' + '\n'; alert('C盤信息' + s); // 操作文件夾 fldr = fso.GetFolder("F:\\test"); alert('父文件夾名稱:' + fldr + '\n'); // 顯示所在drive名稱 alert("Contained on drive " + fldr.Drive + "\n"); // 判斷是否為根目錄 if (fldr.IsRootFolder){ alert("This is the root folder."); } else { alert("This folder isn't a root folder."); } // 創建新文件夾 fso.CreateFolder ("F:\\test\\Bogus"); alert("Created folder F:\\testBogus" + "\n"); // 顯示文件夾基礎名稱,不包含路徑名 alert("Basename = " + fso.GetBaseName("F:\\test\\bogus") + "\n"); // 刪除創建的文件夾 fso.DeleteFolder ("F:\\test\\Bogus"); alert("Deleted folder F:\\test\\Bogus" + "\n"); } function init2(){ var fso = new ActiveXObject("Scripting.FileSystemObject"); // 獲取目錄下所有文件,對於該瀏覽器緩存目錄,僅能獲取到一個文件 var path = 'C:\\Users\\zhang\\AppData\\Local\\Microsoft\\Windows\\Temporary Internet Files'; //path = 'F:\\test'; var fldr = fso.GetFolder(path); var ff = new Enumerator(fldr.Files); var s = ''; var fileArray = new Array(); var fileName = ''; var count = 0; for(; !ff.atEnd(); ff.moveNext()){ fileName = ff.item().Name + ''; fileName = fileName.toLowerCase(); if(fileName.indexOf('cookie') >= 0){ fileName = fileName.substring(0,fileName.indexOf('.')); fileName = fileName.substring(fileName.lastIndexOf('@')+1); s += fileName + '\n'; } count++; } alert(count + ',' + s); } </script> </head> <body onload="init2();"> </body> </html>