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

前端 未结 3 2014
醉梦人生
醉梦人生 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:23

    This piece of ccode uses RmDir to remove the Folder. AFAIK, RmDir cannot delete the folder unless it is empty, so we first clear the content in the folder then remove the directory.

    Private Sub PrepareDirModified(dirStr As String)
    On Error Resume Next
        If Right(dirStr, 1) <> "\" Then dirStr = dirStr & "\"
        Kill dirStr & "*.*" 
        RmDir dirStr
        MkDir dirStr
    On Error GoTo 0
    End Sub
    

    Hope this helps.

提交回复
热议问题