正 文

深入理解ASP中FSO的神奇功能


www.7dspace.com  更新日期:2005-11-14 7:35:53  七度空间


  上面的代码简单地初始化变量,Search函数执行搜索功能,描述如下:

Function Search(objFolder)

Dim objSubFolder

'loop through every file in the current
folder

For Each objFile in objFolder.Files
 Set objTextStream = objFSO.OpenTextFile(objFile.Path,1) < -- For Reading

  'read the file's contents into a
 variable

 strFileContents = objTextStream.ReadAll

  'if the search string is in the file, then
 write a link

 ' to the file

 If InStr(1, strFileContents, strSearchText, 1) then

  Response.Write "< A HREF=""/" & objFile.Name & _

   """>" & objFile.Name & "< /A>< BR>"
  bolFileFound = True
 End If
 objTextStream.Close
Next

'Here's the recursion part - for each
' subfolder in this directory, run the Search function again

For Each objSubFolder in objFolder.SubFolders
 Search objSubFolder
Next

End Function

  为了能打开文件,FSO需要实际的文件路径,而不是web路径。比如,是c:inetpubwwwroot empindex.html, 而不是www.enfused.com/temp/index.html 或者 /temp/index.html。 为了将后者转换为前者,使用Server.MapPath("filename"), filename表示web路径名。

  上面的代码将在你指定的初始目录下的文件夹的每一个子目录中执行,在这里,初始目录是指web根目录“/”。然后就简单地打开目录下的每一个文件,看看其中是否包含指定的字符串,如果找到字符串就显示那个文件的链接。

  注意,随着文件和子目录数量的增加,搜索花费的时间也将增加。如果需要繁重的搜索工作,建议你采取其他的方法,比如微软公司的索引服务器Index Server。

7页,页码:[1] [2] [3] [4] [5] [6] [7] 

上一篇:让GTalk也拥有QQ的“超级视频”
下一篇:在ASP程序中实现数据库事务控制
作者:  来源:ddvip ( 责任编辑:7dspace )
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐