asp删除文件夹目录
2014-08-26来源:易贤网

用asp写了一个函数,asp删除指定文件夹里面的所有内容,看看能看懂么?

<%@language="vbscript"%>

<%Option Explicit%>

<%

'asp获取当前物理路径

Dim foraspcnbase,foraspcndelpath,foraspcntemp,foraspcntemp_array

Dim foraspcnFos'

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

If not IsObject(foraspcnFos) Then response.write ("不支持FOS!,结束!"),response.End()

foraspcnbase = request.ServerVariables("APPL_PHYSICAL_PATH")'获取当前站点物理路径

Function Foraspcn(path)

Dim path_folder,path_array,temp_path,filename,filename_array

If not foraspcnFos.FolderExists(path) Then

Foraspcn = False

Exit Function

End if

'如果是文件夹则开始遍历

Set path_folder = foraspcnFos.GetFolder(path)

set path_array = path_folder.Subfolders'

For each temp_path In path_array

If foraspcn(temp_path) Then

foraspcnFos.DeleteFolder(temp_path)

End if

Next

'删除目前所属文件夹内文件

Set filename = path_folder.files

For each filename_array In filename

foraspcnFos.DeleteFile path&"\"&filename_array.name

Next

Foraspcn = true

End Function

foraspcndelpath = foraspcnbase&"a"'删除根目录下的a文件夹以及里面所有内容

If foraspcn(foraspcndelpath) Then

response.write "删除成功"

Else

response.write "删除失败"

End if

%>

这个有个缺陷是不能删除自身所属文件夹(这理指的是a),再考虑写个新的asp删除文件夹

更多信息请查看IT技术专栏

推荐信息