You are on page 1of 1

Option Explicit

' funcin que borra la carpeta


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function Eliminar_Directorio(Path As String) As Boolean

On Error GoTo Error_Sub

'Variable de tipo file System Object


Dim fso As FileSystemObject

'Creamos la Nueva referencia Fso


Set fso = New FileSystemObject

'Le pasamos a DeleTeFolder el Path a eliminar


fso.DeleteFolder Path, True

If Err.Number = 0 Then
' Ok
Eliminar_Directorio = True
Set fso = Nothing
End If

Exit Function
Error_Sub:

MsgBox Err.Description, vbCritical

End Function

Private Sub Command1_Click()

If Text1 <> "" Then


' Msgbox de Confirmacin de eliminacin
If MsgBox("Seguro que se quiere borrar el directorio " & _
"indicado ??", vbQuestion + vbYesNo) = vbYes Then

' elimina la carpeta


If Eliminar_Directorio(Trim(Text1)) Then
MsgBox "Directorio eliminado", vbInformation
End If
End If
End If
End Sub

Private Sub Form_Load()


Command1.Caption = " Eliminar "
End Sub

You might also like