WEB开发网
开发学院WEB开发ASP asp+fso操作文件例子 阅读

asp+fso操作文件例子

 2009-04-22 10:38:32 来源:WEB开发网   
核心提示:<%@ CODEPAGE="936"%><!--#include file="conn.asp" --><%photoID=request("photoID")sql="select photoFileName from

<%@ CODEPAGE="936"%>
<!--#include file="conn.asp" -->
<%photoID=request("photoID")
sql="select photoFileName from TBL_PHOTO where photoID="&photoID
set rs=conn.execute(sql)
if not rs.eof then
   Set objfso = Server.CreateObject("Scripting.FileSystemObject")
   upfilename=Server.MapPath("upfile/"&rs("photoFileName"))
   'response.Write(upfilename)
   objFSO.DeleteFile(upfilename)
   set objFSO=nothing
end if
rs.close
set rs=nothing

sql="delete from TBL_PHOTO where photoID="&photoID
conn.execute(sql)
conn.close
set conn=nothing
'response.Redirect("photo.asp")
%>
-----------------------------------------------------------------------------
<%
'===================================================

'源码:FSO删除文件示例
'时间:2005年12月17日
'www.cncms.com
'===================================================
Set fs = Server.CreateObject("Scripting.FileSystemObject")
File = Server.MapPath("File1.txt")
on Error Resume Next
fs.DeleteFile File, True '强制删除只读文件
If Err.Number = 53 Then
Response.Write File & "文件不存在!"
Response.End
Elseif Err.Number = 70 Then
Response.Write File & "文件属性为锁定状态!"
Response.End
Elseif Err.Number <> 0 Then
Response.Write "未知错误,错误编码:" & Err.Number
Response.End
Else
Response.Write "成功删除文件!" & File
End If
%>-----------------------------------------------------------------------------
<%Dim rs_del,sql_del
Set rs_del = Server.CreateObject("ADODB.Recordset")
sql_del ="select * from table where upfile_id="&upfile_id
rs_del.open sql_del,conn,1,3
if rs_del.bof and rs_del.eof then
rs_del.close
response.write "<center>没有信息"
Response.End  '终止处理ASP程序,并返回当时的状况
Elsefile1=rs_del("upfile_patch")
If file1 <> "" then
set objfso=server.createobject("scripting.filesystemobject")
file=server.mappath(file1)
objfso.deletefile file
set objfso=Nothing
End Ifrs_del.delete
End if
%>
<script language=javascript>
alert("删除成功!");
location="good.asp"
</script>------------------------------------------------------------------------
<%'删除多个文件的例子
Dim News_id
News_id=request("News_id")
Bigclass=request("Bigclass")
Smallclass=request("Smallclass")
Action=request("Action")
STitle=request("STitle")
Page=request("Page")Dim rs_del,sql_del
Set rs_del = Server.CreateObject("ADODB.Recordset")
sql_del ="select * from News where News_id="&News_id
rs_del.open sql_del,conn,1,3
if rs_del.bof and rs_del.eof then
rs_del.close
response.write "<center>没有信息"
Response.End
ElsesSavePathFileName=replace(rs_del("D_SavePathFileName"),"../../WebsiteUploadFiles/","../WebsiteUploadFiles/")If sSavePathFileName <> "" thenDim aSavePathFileName
aSavePathFileName = Split(sSavePathFileName, "|")set fso=server.createobject("scripting.filesystemobject")
Dim i
For i = 0 To UBound(aSavePathFileName)
file=server.mappath(aSavePathFileName(i))
fso.deletefile file
Next
set fso=Nothing
End Ifrs_del.delete
End ifResponse.Write("<script language=Javascript>alert('删除文章成功!')</script>")
Response.Write("<script language=javascript>window.location='News_manage.asp?Action="& Action &"&STitle="& STitle &"&Bigclass="& Bigclass &"&Smallclass="& Smallclass &"&page="& Page &"'</script>")
Response.Endrs_del.close
set rs_del=Nothing
rs_del.close
set rs_del=Nothing
%>

Tags:asp fso 操作

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接