<%
strText = Request("SearchText")
Const fsoForReading = 1
Dim objFile, objFolder, objSubFolder, objTextStream
strFile = ".asp .htm .html .txt .css"
strRoot = "/"
bolFileFound = False
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.MapPath(strRoot))
response.Write("<table><tr><td>文件名</td><td>最后修改时间</td><td>文件大少</td></tr>")
schSubFol(objFolder)
response.Write("</table>")
function schSubFol(objFolder)
For Each objFile in objFolder.Files
if (instr(strFile,mid(objFile.Name,InstrRev(objFile.Name,".")+1))) then
Set objTextStream = objFSO.OpenTextFile(objFile.Path,fsoForReading)
strContent = objTextStream.ReadAll
If instr(strContent,strText) then
objFilePath=mid(objFile.Path,InstrRev(objFile.Path,"/")+1)
Response.Write "<tr><td> " &objFilePath & "</td><td> " & FormatDateTime(objFile.DateLastModified,1) & "</td><td> " & FormatNumber(objFile.Size / 1024) & "Kbytes</td><tr>"
bolFileFound = True
End If
objTextStream.Close
end if
Next
End function
For Each objSubFolder in objFolder.SubFolders
schSubFol(objSubFolder)
Next
Set objTextStream = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
%>
此博客展示了一段ASP代码,用于在指定目录下搜索包含特定文本的文件。代码通过创建文件系统对象,遍历文件夹及其子文件夹,读取文件内容并检查是否包含搜索文本,若包含则输出文件名、最后修改时间和文件大小。
7327

被折叠的 条评论
为什么被折叠?



