Does anyone have a function that will create a folder multi-level deep? For example I want to create in just one function "C:\My Documents\Level1\Level2\Level3\Level4" and Level1 does not exist.
Please help.
Printable View
Does anyone have a function that will create a folder multi-level deep? For example I want to create in just one function "C:\My Documents\Level1\Level2\Level3\Level4" and Level1 does not exist.
Please help.
Here you go ...
Hope this helps.
Code:Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private Declare Function CreateDirectory Lib "kernel32" _
Alias "CreateDirectoryA" (ByVal lpPathName As String, _
lpSecurityAttributes As SECURITY_ATTRIBUTES) As Long
Public Sub CreateNewDirectory(strNewDirectory As String)
' Example 1: To create a directory structure like "C:\test\directory\vb\tips\
' Call CreateNewDirectory("C:\test\directory\vb\tips\")
'_____________________________________________
' The example shown above will create the following
' Directories/SubDirectories:
'
' C:\TEST
' C:\TEST\DIRECTORY
' C:\TEST\DIRECTORY\VB
' C:\TEST\DIRECTORY\VB\TIPS
'___________________________________________
Dim strDirTest As String
Dim SecAttrib As SECURITY_ATTRIBUTES
Dim blnSuccess As Boolean
Dim strPath As String
Dim intCounter As Integer
Dim strTempDir As String
strPath = strNewDirectory
If Right(strPath, Len(strPath)) <> "\" Then
strPath = strPath & "\"
End If
intCounter = 1
Do Until InStr(intCounter, strPath, "\") = 0
intCounter = InStr(intCounter, strPath, "\")
strTempDir = Left(strPath, intCounter)
strDirTest = Dir(strTempDir)
intCounter = intCounter + 1
'create directory
SecAttrib.lpSecurityDescriptor = &O0
SecAttrib.bInheritHandle = False
SecAttrib.nLength = Len(SecAttrib)
blnSuccess = CreateDirectory(strTempDir, SecAttrib)
Loop
End Sub
[Edited by jcouture100 on 06-16-2000 at 09:10 AM]
Or a rather simpler way of doing things.
Code:Private Sub Command1_Click()
mkDirStructure (Text1.Text)
End Sub
Private Sub mkDirStructure(stDir As String)
If Dir$(stDir, vbDirectory) = "" Then
mkDirStructure (Mid$(stDir, 1, InStrRev(stDir, "\") - 1))
mkDir stDir
End If
End Sub
Thank you very much guys. It really help a lot.
or you can try this
if u want to create a folder like:
C:\dfgd\dgdg\fgdg\
then make some file (makes no diffrence what file) and save it to
C:\dfgd\dgdg\fgdg\
I think that works but this is bad just incase u dont get a good answer
REMEMBER IF YOU DONT SUCCEED TYPE AND TYPE AGAIN and if that doesnt work find a way around it ;)