Remove directory and it's contents (files, subdirectories) without using FileSystemObject

前端 未结 3 2013
醉梦人生
醉梦人生 2020-12-11 17:44

I want to know if it\'s possible to rewrite this piece of code:

Private Sub PrepareDir(ByVal dir As String)
    Dim fso As New FileSystemObject
    If fso.Fo         


        
3条回答
  •  没有蜡笔的小新
    2020-12-11 18:24

    The OP said they want to rewrite their code "without FSO" but it doesn't make sense.

    If the goal is to reduce the amount of code, simply make it a one-liner:

    CreateObject("Scripting.FileSystemObject").DeleteFolder "x:\myFolder"
    

    As requested, this permanently removes the folder and it's contents.


    More Information:

    • Microsoft Docs : DeleteFolder Method
    • Ron de Bruin : Delete files and folders

提交回复
热议问题