2008-06-20, 11:51 AM
|
#14 (permalink)
|
長老會員
|
我做了一些修改, 已經可以查子目錄了, 也可以直接執行點選找到的檔案...
另外, 關於安全性的問題, 那是微軟搞的...無解
語法:
<HTML lang=zh-TW>
<HEAD>
<TITLE>本機 檔案搜尋</TITLE>
<META http-equiv=Content-Type content="text/html; charset=big5">
</HEAD>
<style>
.Field {color: black; border: 1px solid #FFFFFF; background-color: #FFCC00;}
.Find {color:blue; font: 12px Arial;}
</style>
<script>
var Fo =new ActiveXObject("Scripting.FileSystemObject");
var StrOut = new String();
var FileName = new String();
var Extention = new String();
var LimitFilesByDirectory = 100; //1個目錄內最多要檢查的檔案數...
var LimitFoldersByDirectory = 10; //1個目錄內最多要檢查的子目錄數...
function FindFile(FOo)
{
cwvdavid_fileRead = new ActiveXObject("Scripting.FileSystemObject");
var FSo = new Enumerator(FOo.Files); //取得 該目錄下的所有檔案...
var subFOo = new Enumerator(FOo.SubFolders); //取得該目錄下的所有目錄...
for(i=0;!FSo.atEnd();FSo.moveNext())
{
if(FileName == "*" || FSo.item().name.slice(0,FSo.item().name.lastIndexOf(".")).toLowerCase().indexOf(FileName)>-1)
{
if(Extention == "*" || FSo.item().name.slice(FSo.item().name.lastIndexOf(".")+1).toLowerCase().indexOf(Extention)>-1)
{
hasWord = "[x]";
//把找到的檔案列出來...
//路徑的尾巴要加\, 不然找不到
mypath = FOo.Path;
//檢查mypath的尾巴是否有\, 如果沒有就加上去...
if(mypath.lastIndexOf("\\")+1 != mypath.length)
{
mypath = mypath + "\\";
}
ts = cwvdavid_fileRead.OpenTextFile(mypath + FSo.item().name, 1);
myReadWord = ts.ReadAll();
if(myReadWord.indexOf(searchWord.value) != -1)
{
//如果有找到文字...就列出該檔案
StrOut += "<tr "+ ((i%2)? "":"bgcolor=#DDAA55") +"><td width=20%><font class=find>" + FOo.Path + "</font></td><td width=30%><font class=find><a target=\"_blank\" href=\"" + mypath + FSo.item().name + "\">" + FSo.item().name + "</a></font></td><td width=25%><font class=find>" + FSo.item().type + "</font></td><td width=50%><font class=find>"+ String(FSo.item().size/(1024*1024)).slice(0,3) +" MB</font></td></tr>";
}
ts.Close();
i++
if(i >= LimitFilesByDirectory) break; //同一層的檔案只找前面 n 個...避免太多...沒完沒了...(尤其是誤選了什麼某個... I386的目錄)
}
}
}
//找完檔案開始找資料夾...
for(i=0;!subFOo.atEnd();subFOo.moveNext())
{
FindFile(Fo.GetFolder(subFOo.item().Path)); //使用遞迴.....
i++;
if(i >= LimitFoldersByDirectory) break; //同一層目錄只找前 n 個子目錄...避免太多...沒完沒了...
}
}
function Scan()
{
FileName = (search.value.lastIndexOf(".")>-1)? search.value.slice(0,search.value.lastIndexOf(".")):(search.value.length>0)? search.value.toLowerCase():"*"; //Get Searched File Name
Extention = (search.value.lastIndexOf(".")>-1)? search.value.slice(search.value.lastIndexOf(".")+1).toLowerCase():"*"; // Get Searched File Extention Name
if(path.value.length>0 && Fo.FolderExists(path.value))
{
StrOut = "<table border=0 width=100% cellspacing=0>"
StrOut += "<tr bgcolor=\"#CCCCCC\"" +"><td width=20%><font class=find>路徑</font></td><td width=30%><font class=find>檔名</font></td><td width=25%><font class=find>檔案類型</font></td><td width=50%><font class=find>檔案大小</font></td></tr>";
outPut.innerHTML = StrOut;
FindFile(Fo.GetFolder(path.value));
outPut.innerHTML = StrOut+"</table>";
}
else alert("錯誤的路徑...");
}
</script>
<BODY topmargin="0" leftmargin="0">
<table border=0 width=100% cellspacing="0" style="border-collapse: collapse" cellpadding="2"><tr>
<td dir="ltr" bgcolor="#FFCC00"><b><font face="Arial" size="2">Named :</font></b></td>
<td dir="ltr" bgcolor="#FFCC00">
<input size=50 type=text id=search name=search class="Field" value="*.html"></td>
</tr><tr>
<td dir="ltr" bgcolor="#FFCC00">
<p dir="ltr"><b><font face="Arial" size="2">Path : </font></b> </td>
<td bgcolor="#FFCC00">
<input size=50 type=text value="C:\testHtml" id=path name=path class="Field" ></td>
</tr><tr>
<td bgcolor="#FFCC00">要找的文字...</td>
<td bgcolor="#FFCC00">
<input size=50 type=text value="文字" id=path0 name=searchWord class="Field" ></td>
</tr><tr>
<td bgcolor="#FFCC00"> </td>
<td bgcolor="#FFCC00">
<input type=button value=" Scan " onclick=Scan() class="Field"></td>
</tr><tr>
<td colspan=2 align=right bgcolor="#FFCC00"><font face=arial size=2><b>Search Result</b></font><hr></td>
</tr><tr>
<td colspan=2 bgcolor="#FFCC00">
<div id=outPut>
</div>
</td>
</tr></table>
</BODY>
</HTML>
|
__________________
姜太公釣魚~ 願者上鉤
|
|
送花文章: 4036,
收花文章: 2466 篇, 收花: 10141 次
|