VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Create a multi-level directory structure using CreateDirectory API call

by Anonymous (267 Submissions)
Category: Windows System Services
Compatability: Visual Basic 4.0 (32-bit)
Difficulty: Unknown Difficulty
Originally Published: Wed 1st September 1999
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Create a multi-level directory structure using CreateDirectory API call

API Declarations



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


Rate Create a multi-level directory structure using CreateDirectory API call



Public Sub CreateNewDirectory(NewDirectory As String)
    Dim sDirTest As String
    Dim SecAttrib As SECURITY_ATTRIBUTES
    Dim bSuccess As Boolean
    Dim sPath As String
    Dim iCounter As Integer
    Dim sTempDir As String
    iFlag = 0
    sPath = NewDirectory
    
    If Right(sPath, Len(sPath)) <> "\" Then
        sPath = sPath & "\"
    End If
    
    iCounter = 1
    
    Do Until InStr(iCounter, sPath, "\") = 0
        iCounter = InStr(iCounter, sPath, "\")
        sTempDir = Left(sPath, iCounter)
        sDirTest = Dir(sTempDir)
        iCounter = iCounter + 1
        'create directory
        SecAttrib.lpSecurityDescriptor = &O0
        SecAttrib.bInheritHandle = False
        SecAttrib.nLength = Len(SecAttrib)
        bSuccess = CreateDirectory(sTempDir, SecAttrib)
    Loop

End Sub

'call to create a new directory
Call CreateNewDirectory("c:\mydir\testing\visual basic\")

Download this snippet    Add to My Saved Code

Create a multi-level directory structure using CreateDirectory API call Comments

No comments have been posted about Create a multi-level directory structure using CreateDirectory API call. Why not be the first to post a comment about Create a multi-level directory structure using CreateDirectory API call.

Post your comment

Subject:
Message:
0/1000 characters