ASP中FSO组件的属性和方法(四)-

下面是一个利用FSO创建文件,和向里面写入数据的实例教程!


<%
Dim fs, serverPath, filePath, txts
Set fs = Server.CreateObject("Scripting.FileSystemObject")
ForAppending = 8 '打开用于读写
serverPath = Server.MapPath(".")
'映射系统物理路径,Server.MapPath(".")表示当前目录
filePath = serverPath &  "/GAMVANfile/"
'获取物理路径在是新建文件存在当前目录下GAMVANfile文件夹里面!
if not fs.FolderExists(filePath) then
fs.CreateFolder(filePath)
end if
'检测文件夹是否存在,没有则自动创建!
txts = "<hr height='1'>春眠不觉晓,<br>处处蚊子咬!"&_
"<br><br><a href=''>www.GAMVAN.com</a>"&_
"<br><br>更新时间:" &  now() &  "<hr>"

Dim f, fName
fName = filePath&"GAMVAN.htm"
if fs.FileExists(fName) then
Set f = fs.OpenTextFile(fName, ForAppending, True)
else
Set f = fs.CreateTextFile(fName, ForWriting, false)
end if
'上面七行代码是判断fName文件是否存在如果存在就打开它用于读写,否则就自动创建
f.Write(txts)
f.Close
Set f = Nothing
Response.Write fName &  " 创建成功!"
%>


其实上面这个代码就是静态网站发布系统的最原始的原理,那些可以生成HTML的新闻发布系统都是依循这个原理设计的……

关于TextSteam其他属性方法就是大同小异,依此例类推即可!

以上源代码在 WIN XP + IIS5.0 测试通过!

接下来的文章我们将介绍File、Folder、Driver对象的属性和方法!

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值