Saltar al contenido

Macro eliminar un directorio cuya ruta esta en a1

Featured Replies

publicado

Sub EliminarCarpeta(): On Error Resume Next
Kill [A1].Value & "\*.*" ' Elimina todos los archivos de la carpeta
RmDir [A1].Value ' Elimina la carpeta
End Sub
[/CODE]

publicado

Pero si dentro de la carpeta tienes subdirectorios, esos no los borra, aguas con ello! Aun asi muy buen codigo!

publicado
Pero si dentro de la carpeta tienes subdirectorios, esos no los borra, aguas con ello! Aun asi muy buen codigo!

Delete files and folders

Sub Clear_All_Files_And_SubFolders_In_Folder()
'Delete all files and subfolders
'Be sure that no file is open in the folder
Dim FSO As Object
Dim MyPath As String

Set FSO = CreateObject("scripting.filesystemobject")

MyPath = "C:\Users\Ron\Test" '<< Change

If Right(MyPath, 1) = "\" Then
MyPath = Left(MyPath, Len(MyPath) - 1)
End If

If FSO.FolderExists(MyPath) = False Then
MsgBox MyPath & " doesn't exist"
Exit Sub
End If

On Error Resume Next
'Delete files
FSO.deletefile MyPath & "\*.*", True
'Delete subfolders
FSO.deletefolder MyPath & "\*.*", True
On Error GoTo 0

End Sub[/CODE]

Archivado

Este tema está ahora archivado y está cerrado a más respuestas.