如何用ASP,删除指定UpLoadFile中的所有文件,并提示删除成功!
展开全部
经脚本之家编辑测试如下:
<%
'del.asp
dim fso,tmpfolder,tmpsubfolder,tmpfile,tmpfiles
set fso=server.CreateObject("Scripting.FileSystemObject")
sub delfolder(sPath)
If (fso.FolderExists(server.MapPath (sPath))) then
set tmpfolder=fso.GetFolder(server.MapPath (sPath))
set tmpfiles=tmpfolder.files
for each tmpfile in tmpfiles
thename=tmpfile
fso.DeleteFile (tmpfile)
If Err.number=0 then
response.write thename&" <font color=red>文件删除成功</font><br>"
End if
next
set tmpsubfolder=tmpfolder.SubFolders
for each tmpfolder in tmpsubfolder
infoname=spath&"/"&tmpfolder.name
delfolder(spath&"/"&tmpfolder.name)
If Err.number=0 then
response.write infoname&" <font color=red>删除成功</font><br>"
End if
next
fso.DeleteFolder (server.MapPath (sPath))
end if
end sub
'调用例子
'del.asp放到要删除的目录同一层,要删除的目录存在且其下有若干子目录和文件,要对该目录具有修改权限。
delfolder("JSON")
%>
<%
'del.asp
dim fso,tmpfolder,tmpsubfolder,tmpfile,tmpfiles
set fso=server.CreateObject("Scripting.FileSystemObject")
sub delfolder(sPath)
If (fso.FolderExists(server.MapPath (sPath))) then
set tmpfolder=fso.GetFolder(server.MapPath (sPath))
set tmpfiles=tmpfolder.files
for each tmpfile in tmpfiles
thename=tmpfile
fso.DeleteFile (tmpfile)
If Err.number=0 then
response.write thename&" <font color=red>文件删除成功</font><br>"
End if
next
set tmpsubfolder=tmpfolder.SubFolders
for each tmpfolder in tmpsubfolder
infoname=spath&"/"&tmpfolder.name
delfolder(spath&"/"&tmpfolder.name)
If Err.number=0 then
response.write infoname&" <font color=red>删除成功</font><br>"
End if
next
fso.DeleteFolder (server.MapPath (sPath))
end if
end sub
'调用例子
'del.asp放到要删除的目录同一层,要删除的目录存在且其下有若干子目录和文件,要对该目录具有修改权限。
delfolder("JSON")
%>
追问
功能能实现,但这样把UpLoadFile文件夹也删除了,我想保留UpLoadFile文件夹,上面的代码如何修改?
追答
其实简单,最后新建一个文件夹就可以了
文件删除成功"
End if
next
set tmpsubfolder=tmpfolder.SubFolders
for each tmpfolder in tmpsubfolder
infoname=spath&"/"&tmpfolder.name
delfolder(spath&"/"&tmpfolder.name)
If Err.number=0 then
response.write infoname&" 删除成功"
End if
next
fso.DeleteFolder (server.MapPath(sPath))
fso.createfolder(server.MapPath(sPath))
end if
end sub
'调用例子
'del.asp放到要删除的目录同一层,要删除的目录存在且其下有若干子目录和文件,要对该目录具有修改权限。
delfolder("JSON")
%>
参考资料: http://www.jb51.net/article/10600.htm
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询