在线等待,如何删除一个目录下的所有子目录及文件,不有FileSystemObject

解决方案 »

  1.   

    Kill 支* 和? 的统配符来指定多重文件。
      

  2.   

    Option ExplicitPrivate Type SHFILEOPSTRUCT
        hwnd As Long
        wFunc As Long
        pFrom As String
        pTo As String
        fFlags As Integer
        fAnyOperationsAborted As Long
        hNameMappings As Long
        lpszProgressTitle As String '  only used if FOF_SIMPLEPROGRESS
    End TypePrivate Const FO_DELETE As Long = &H3
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Private Declare Function SHFileOperation Lib "Shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As LongPrivate Sub Command1_Click()
        Dim fileop As SHFILEOPSTRUCT
        Dim sfile As String
        Dim params As String
        Dim hWndDesk As Long, result As Long
        
        With fileop
            params = vbNullString
            hWndDesk = GetDesktopWindow()
            
            sfile = "d:\aa" '要删除的文件或文件
            
            .hwnd = Me.hwnd
            .wFunc = FO_DELETE
            .pFrom = sfile & vbNullChar & vbNullChar
            result = SHFileOperation(fileop)
            
            If result <> 0 Then
                MsgBox "对不起,操作失败!", vbExclamation
            Else
                If fileop.fAnyOperationsAborted <> 0 Then
                    MsgBox "对不起,操作失败!", vbExclamation
                End If
            End If
            DoEvents
        End WithEnd Sub
      

  3.   

    这是调用Windows的删除进程,很专业的~~