« 牡丹江 | Main | tamade! »

asp删除非空目录的例子

这是个删除非空目录的例子

'test.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
fso.DeleteFile (tmpfile)
next
set tmpsubfolder=tmpfolder.SubFolders
for each tmpfolder in tmpsubfolder
'response.Write spath&"/"&tmpfolder.name

delfolder(spath&"/"&tmpfolder.name )
next
fso.DeleteFolder (server.MapPath (sPath))
end if
end sub
%>
<%
'调用例子
'test.asp放到wwwroot\下
'wwwroot\1\存在,且其他下有若干子目录和文件
delfolder("1")
%>

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on November 8, 2005 3:38 AM.

The previous post in this blog was 牡丹江.

The next post in this blog is tamade!.

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.