<BR> 到此,你对FSO可能已经有了很好的体会。让我们再深入研究一步,来解决更复杂的难题。<BR><BR> 首先,你可能希望对文件改名。为了跟踪所有的文档,你将要重新命名它们以便唯一,这样就可以被系统容易地区<BR>别。很不幸,FSO不允许简单的文件改名操作,所以我们不得不修改一下。<BR><BR>< %<BR>' create the fso object<BR>set fso = Server.Createobject("Scripting.FileSystemObject")<BR>path = "c: emp est.txt"<BR>strDate = Replace(Date(), "/", "")<BR>strDir = "c:inetpubwwwrootarticles" & strDate<BR>strNewFileName = Hour(Now) & "_" & Minute(Now) & "_" &<BR>second(Now) & ".html"<BR><BR>' open the old file<BR>set file = fso.opentextfile(path, 1) < -- For reading<BR>strText = file.readall<BR>set file = nothing<BR><BR>' check for and/or create folder<BR>if not fso.folderexists(Server.MapPath(strDir)) then<BR>set f = fso.CreateFolder(Server.MapPath(strDir))<BR>else<BR>set f = fso.GetFolder(Server.MapPath(strDir))<BR>end if<BR><BR>' create and write new file<BR>set file = fso.Createtextfile(f.path & "" & strNewFileName)<BR>file.write(strText)<BR>set f = nothing<BR>file.close<BR>set file = nothing<BR><BR>' delete the old file<BR>fso.DeleteFile(path & "" & rst("FileName") & i)<BR>' clean up<BR>set fso = nothing<BR>%><BR><BR> FSO能力的不足在这里却成了优势,我们可以一次执行2步。首先,打开文件并读入文件的内容。假设这里要创建一个<BR>唯一的文件夹和一个唯一的文件来存储文章。然而,因为文件夹的路径每天都将改变,所以必须首先检查是否文件夹已经<BR>存在,如果不存在,就创建它。这在if not fso.folderexists代码段完成。然后,取得那个路径,创建一个新的文件。新<BR>文件建立完成后,删除掉旧文件,这通过fso.DeleteFile来完成。<BR><BR> 这2步就是:对文件改名,然后移动到一个更合适的目录下。注意,在这里还可以对文件进行更多地操作,比如在写<BR>入新文件前进行一下内容的编辑。 <BR>
