Mostrando Codigo - Visual Basic

Eliminar un directorio y todo su contenido

Para borrar un directorio con todo su contenido podemos aplicar este codigo. Simplemente debemos modificar la linea 2 con el nombre y parth del directorio, y todo el contenido será eliminado. En el ejemplo el directorio será eliminado a la carga del formulario, por lo que debes tener cuidado :-) del directorio que indicas.
Visitas: 15862 - 08/05/2004 22:10:28
CODIGO SIN DEMOSTRACIONCODIGO NO EJECUTABLENO CONTIENE ARCHIVO DESCARGABLE
CODIGO


// Codigo ofrecido por Tutores.org
Private Sub Form_Load()
x = DelTree("C:midirectorio")
Select Case x
Case 0: MsgBox "Eliminado"
Case -1: MsgBox "Directorio invalido"
Case Else: MsgBox "Ha ocurrido un error"
End Select
End Sub

Function DelTree(ByVal strDir As String) As Long
Dim x As Long
Dim intAttr As Integer
Dim strAllDirs As String
Dim strFile As String
DelTree = -1
On Error Resume Next
strDir = Trim$(strDir)
If Len(strDir) = 0 Then Exit Function
If Right$(strDir, 1) = "" Then strDir = Left$(strDir, Len(strDir) - 1)
If InStr(strDir, "") = 0 Then Exit Function
intAttr = GetAttr(strDir)
If (intAttr And vbDirectory) = 0 Then Exit Function
strFile = Dir$(strDir & "*.*", vbSystem Or vbDirectory Or vbHidden)
Do While Len(strFile)
If strFile <> "." And strFile <> ".." Then
intAttr = GetAttr(strDir & "" & strFile)
If (intAttr And vbDirectory) Then
strAllDirs = strAllDirs & strFile & Chr$(0)
Else
If intAttr <> vbNormal Then
SetAttr strDir & "" & strFile, vbNormal
If Err Then DelTree = Err: Exit Function
End If
Kill strDir & "" & strFile
If Err Then DelTree = Err: Exit Function
End If
End If
strFile = Dir$
Loop
Do While Len(strAllDirs)
x = InStr(strAllDirs, Chr$(0))
strFile = Left$(strAllDirs, x - 1)
strAllDirs = Mid$(strAllDirs, x + 1)
x = DelTree(strDir & "" & strFile)
If x Then DelTree = x: Exit Function
Loop
RmDir strDir
If Err Then
DelTree = Err
Else
DelTree = 0
End If
End Function

ENLACE AL CODIGO
Si quieres enlazar desde tu pagina a este codigo
<!-- Inicio enlace Tutores.org -->
<a title="Tutores.org - Eliminar un directorio y todo su contenido" href="http://www.tutores.org/codigo/1062/" target="_blank">Eliminar un directorio y todo su contenido</a>
<!-- Final enlace Tutores.org -->
COMENTARIOS
camilo
hola quisiera saber si en el momento de ejecutar solamente la ruta c:
borra todo el contenido en c
thakns
escribir a aeruials182@hotmail.com
camilo
escribir a aerials1822000@hotmail.com
quedo mal escrito el correop anteriormente
gracias
Carlos 01/05/2004 16.50.01
Siento decirlo, pero no me funciona este código.
Nose que puede pasar. Me dice que en la línea 10 falta un ')'.

Gracias por la ayuda.
paulo 09-05-2008 21:58:51
tengo VB 6 portable y me funciono muy bien, hice una prueba justo al teminar la descarga
lol
Carlo si te falata ')' es por que debes finalizar la expresio con ese simbolo :D
INSERTAR COMENTARIO

Usuario:
Email:
Comentario:
Codigo Seguridad


Antes de enviar un comentario...
Todos los comentarios son revisados personalmente
Todo comentario que no haga relacion al codigo mostrado en esta pagina sera eliminado

Usuarios registrados tienen preferencia en recibir respuestas de ayuda!!
Ademas de poder insertar Imagenes,Enlaces y otras propiedades del editor.
Por favor, insertar los comentarios descriptivos.