懂asp代码的来..谢谢喽

来源:百度知道 编辑:UC知道 时间:2024/05/26 16:02:10
运行asp页面之后
删除本目录下的123.htm
新建一个空白的123.htm
怎么写代码?

<%
set fso=server.createobject("Scripting.FileSystemObject")'建立文件对象
filepath=server.mappath(".")+"\123.htm"'生成文件路径
if fso.FileExists(filepath) then'判断文件是否存在。
fso.deletefile(filepath)'文件存在时,删除文件
else
fso.createtextfile(filepath)'文件不存在时,建立文件
end if
%>

Set fs = server.CreateObject("scripting.filesystemobject")

filename = Server.MapPath("123.htm")

if fs.FileExists(filename) then
fs.DeleteFile(filename)
end if
set myfile = fs.CreateTextFile(filename,true)
dim strLine,responsestr
strLine=""
myfile.writeline strLine
set myfile = nothing
Set fs=Nothing

不用删除,创建的时候直接覆盖就可以了

既然文件名和扩展名都一样,为什么要删除再建呢?直接重写内容就行了。