用asp寫了一個函數(shù),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技術專欄