日期:2014-05-17  浏览次数:20745 次

新手求教,ASP内置组件文件操作相关
刚学完内置组件文件操作的一些东西,就想做一个页面可以实现输入指定文件名称以后删除该文件的功能,但是遇到了一些问题,比如<% alert("") %> 为什么不能执行呢?不是说vbs的代码在<% %>里都可以执行的么?然后在<% %>标签里的函数好像也没有被调用。只有不使用asp内置组件并且用<script> </script>标签函数才能被调用。为什么只有一部分vbs的代码才能在<% %>里使用呢?很困惑啊,不止是在本机的iis7上不行,上传到3v.com的免费空间也一样。求指导,谢谢。

代码如下:
<body>
<%
sub b1_onclick()
dim filename
filename=t1.value
set fso=server.CreateObject("scripting.filesystemobject")
if fso.fileexists(server.MapPath(filename)) then
fso.filedelete(filename)
alert("删除成功")
else
alert("该文件不存在")
end if
end sub
%>

<table align="center">
<tr><td>请输入你想从网站根目录删除的文件名称</td></tr>
<tr><td>
<input name=t1 type="text" value="pppp.jpg"/>
<input name=b1 type="button" value="submit(确认)" onclick="b1_onclick()"/>
</td></tr>
</table>
</body>

------解决方案--------------------
新手还没区分vb,vbscript,javascript,asp呀。还是好好学习一下吧
JScript code
<%
dim filename
filename=Request.Form("f1")
If filename<>"" Then 
    set fso=server.CreateObject("scripting.filesystemobject")
    if fso.fileexists(server.MapPath(filename)) then
    fso.filedelete(filename)
    Response.write "<script>alert('删除成功')</script>"
    Else
    Response.write "<script>alert('该文件不存在')</script>"
    end if
end if
%>