Verificar y Crear Ruta


/ Published in: Visual Basic
Save to your folder(s)



Copy this code and paste it in your HTML
  1. Public Sub VerificarRutaArchivo(RutaArchivo As String)
  2.  
  3. On Error GoTo ErrSub
  4.  
  5. Dim i As Integer
  6. Dim Array_Dir As Variant
  7. Dim Sub_Dir As String
  8. Dim El_Path As String
  9.  
  10. El_Path = RutaArchivo 'InputBox(" Escribir la ruta del directorio a crear " & _
  11.   "con los subdirectorios", _
  12.   " Crear varios niveles de directorios")
  13.  
  14. If El_Path = vbNullString Then
  15. Exit Sub
  16. End If
  17.  
  18. 'Desglosa el path y llena el array con los _
  19.   subdirectorios que se irán creando
  20. Array_Dir = Split(El_Path, "\")
  21.  
  22. El_Path = vbNullString
  23.  
  24. 'Recorre el vector anterior para ir creando uno por uno _
  25.   comenzando obviamente desde el directorio de primer nivel
  26. For i = LBound(Array_Dir) To UBound(Array_Dir)
  27. Sub_Dir = Array_Dir(i)
  28. If Sub_Dir <> vbNullString Then
  29. El_Path = El_Path & Sub_Dir & "\"
  30. If Right$(Sub_Dir, 1) <> ":" Then
  31. ' Verificamos que no exista
  32. If Dir(El_Path, vbDirectory) = vbNullString Then
  33. 'Crea la carpeta
  34. Call MkDir(El_Path)
  35. End If
  36. End If
  37. End If
  38. Next
  39.  
  40. ' MsgBox " Directorio creado ", vbInformation
  41.  
  42. 'Error
  43. Exit Sub
  44. ErrSub:
  45.  
  46. MsgBox "Número de error: " & Err.Number & _
  47. "Descripción del error: " & Err.Description, vbCritical
  48.  
  49. End Sub
  50.  

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.