Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. Sub makeDir(path As String)
  2. Dim ps As String: ps = Application.PathSeparator
  3. If Right(path, 1) = ps Then path = Left(path, Len(path) - 1)
  4. Dim parent As String: parent = Left(path, InStrRev(path, ps))
  5. If Dir(parent, vbDirectory) = "" Then makeDir parent
  6. MkDir path
  7. End Sub
  8.  
  9. 'Return the path so you can use `path = makeDir(newpath)
  10. Function makeDir(path As String) As String
  11. Dim hasPS As Boolean
  12. Dim ps As String: ps = Application.PathSeparator
  13. If Dir(path, vbDirectory) = "" Then
  14. If Right(path, 1) = ps Then
  15. path = Left(path, Len(path) - 1)
  16. hasPS = True
  17. End If
  18. makeDir Left(path, InStrRev(path, ps))
  19. MkDir path
  20. End If
  21. If hasPS Then
  22. makeDir = path & ps
  23. Else
  24. makeDir = path
  25. End If
  26. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement