【ASP】递归清空目录下所有文件和子目录

  • A+
所属分类:lcx

可能删不干净版:

'On Error Resume Next
ClearFile Server.MapPath("") '清空当前目录除自身外所有文件

Function ClearFile(Path) '清空目录所有文件
Dim Fso,ObjFolder,ObjFile 'Fso对象,子目录对象,文件对象
Set Fso=Server.CreateObject("scripting.filesystemObject") '创建FSO读写对象
For Each ObjFile in Fso.GetFolder(Path).Files '读取当前目录下的文件
    Response.Write "文件:" & Path & "" & ObjFile.Name & " --> 删除成功!
"
    'If Replace (Lcase(Path & "" & ObjFile.Name),"","") Lcase(Server.MapPath(Request.ServerVariables("SCRIPT_NAME"))) Then
    Fso.DeleteFile Path & "" & ObjFile.Name
Next
For Each ObjFolder In Fso.GetFolder(Path).SubFolders '读取子目录
    Response.Write "目录:" & Path & "" & ObjFolder.Name & " --> 删除成功!
"
    Fso.DeleteFolder Path & "" & ObjFolder.Name,true
Next
Response.Write "
目录:" & Path & " 清空完毕。完成时间:" & Now() & ""
End Function
%>

可以完全清理版:

'On Error Resume Next
ClearFile Server.MapPath("./") '清空当前目录除自身外所有文件

Function ClearFile(Path) '清空目录所有文件
Dim Fso, ObjFolder, ObjFile 'Fso对象,子目录对象,文件对象
Set Fso = Server.CreateObject("scripting.filesystemObject") '创建FSO读写对象
For Each ObjFile in Fso.GetFolder(Path).Files '读取当前目录下的文件
    If Replace (Lcase(Path & "" & ObjFile.Name),"","") Lcase(Server.MapPath(Request.ServerVariables("SCRIPT_NAME"))) Then
        Response.Write "文件:" & Path & "" & ObjFile.Name & " --> 删除成功!
"
        Fso.DeleteFile Path & "" & ObjFile.Name
    End IF
Next
For Each ObjFolder In Fso.GetFolder(Path).SubFolders '读取子目录
    ClearFile Path & "" & ObjFolder.Name
    Response.Write "目录:" & Path & "" & ObjFolder.Name & " --> 删除成功!
"
    Fso.DeleteFolder Path & "" & ObjFolder.Name,true
Next
Response.Write "目录:" & Path & " ---> 清空完毕。完成时间:" & Now() & "
"
End Function
%>

文章来源于lcx.cc:【ASP】递归清空目录下所有文件和子目录

相关推荐: 双系统的UEFI引导方案及失败后的修复方法

接上文:教程:如何无损从MBR引导更改为UEFI 本教程需要用到前篇文章中的工具,如果没有请到上文下载。这里不另外发了。 双系统UEFI引导设置: 请先下载bcdtice,这个工具上文没有,在这里发出:BOOTICEx86.zip(三方工具,病毒自测,谨慎使用…

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: