' open the file set file =
fso.opentextfile(path, ForAppending, TRUE)
' write the info to the
file file.write(strName) & vbcrlf file.write(strHomePage)
& vbcrlf file.write(strEmail) & vbcrlf
' close and
clean up file.close set file = nothing set fso = nothing
回想一下,OpenTextFile方法返回一个TextStream对象,它是FSO模型中的另外一个对象。TextStream对象揭示了操作文件内容的方法,比如写、读一行、跳过一行。VB常量vbcrlf产生一个换行符。
strSearchText = Request.Form("SearchText") < -- The search string
' create the FSO and Folder objects Set fso =
Server.CreateObject("Scripting.FileSystemObject") Set objFolder =
objFSO.GetFolder(Server.MapPath("/"))
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路径名。