Results 1 to 5 of 5

Thread: Help: Create folders

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    Philippines
    Posts
    5

    Question

    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.


  2. #2
    Addicted Member jcouture100's Avatar
    Join Date
    Aug 1999
    Posts
    141

    Wink

    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]
    JC

  3. #3
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    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
    Iain, thats with an i by the way!

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    Philippines
    Posts
    5

    Cool

    Thank you very much guys. It really help a lot.

  5. #5
    Lively Member
    Join Date
    Jun 2000
    Posts
    67
    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width