到此,您对FSO可能已有了很好的体会。让我们再深入研究一步,来解决更复杂的难题。

   首先,您可能希望对文档改名。为了跟踪任何的文档,您将要重新命名他们以便唯一,这样就能够被系统容易地区
别。很不幸,FSO不允许简单的文档改名操作,所以我们不得不修改一下。

< %
' create the fso object
set fso = Server.Createobject("Scripting.FileSystemObject")
path = "c: emp est.txt"
strDate = Replace(Date(), "/", "")
strDir = "c:inetpubwwwrootarticles" & strDate
strNewFileName = Hour(Now) & "_" & Minute(Now) & "_" &
second(Now) & ".html"

' open the old file
set file = fso.opentextfile(path, 1) < -- For reading
strText = file.readall
set file = nothing

' check for and/or create folder
if not fso.folderexists(Server.MapPath(strDir)) then
set f = fso.CreateFolder(Server.MapPath(strDir))
else
set f = fso.GetFolder(Server.MapPath(strDir))
end if

' create and write new file
set file = fso.Createtextfile(f.path & "" & strNewFileName)
file.write(strText)
set f = nothing
file.close
set file = nothing

' delete the old file
fso.DeleteFile(path & "" & rst("FileName") & i)
' clean up
set fso = nothing
%>

   FSO能力的不足在这里却成了优势,我们能够一次执行2步。首先,打开文档并读入文档的内容。假设这里要创建一个
唯一的文档夹和一个唯一的文档来存储文章。然而,因为文档夹的路径每天都将改变,所以必须首先检查是否文档夹已
存在,假如不存在,就创建他。这在if not fso.folderexists代码段完成。然后,取得那个路径,创建一个新的文档。新
文档建立完成后,删除掉旧文档,这通过fso.DeleteFile来完成。

   这2步就是:对文档改名,然后移动到一个更合适的目录下。注意,在这里还能够对文档进行更多地操作,比如在写
入新文档前进行一下内容的编辑。