【asp是什么意思】ASP中FSO的神奇功能 - 用FSO进行内容管理

时间:2014-02-08  来源:Yahoo研究  阅读:
作 者 : 甘冀平
   到此,你对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步就是:对文件改名,然后移动到一个更合适的目录下。注意,在这里还可以对文件进行更多地操作,比如在写
入新文件前进行一下内容的编辑。

【asp是什么意思】ASP中FSO的神奇功能 - 用FSO进行内容管理

http://m.bbyears.com/seo/4030.html

推荐访问:asp文件 asp什么意思
相关阅读 猜你喜欢
本类排行 本类最新