Results 1 to 10 of 10

Thread: Create multiple subdirectories

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Posts
    149

    Create multiple subdirectories

    Hi,

    Does anyone know any tactics or API that can create
    multiple subdirectories ?
    The current 'mkdir' command can only make 1 directory at a time.
    I want to make the multiple subdirectories like C:\test1\test2\test3

    Thanks in advance.

  2. #2

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Create multiple subdirectories

    You can do that via one API call:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function MakeSureDirectoryPathExists _
    4.     Lib "imagehlp.dll" (ByVal lpPath As String) As Long
    5.  
    6. Private Sub Command1_Click()
    7.     'NOTE: make sure complete path ends with backslash
    8.     MakeSureDirectoryPathExists "c:\dir1\subdir1\subdir2\"
    9. End Sub

  4. #4
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Slightly off-topic

    @RhinoBull : What does the imagehlp.dll do ? Does it come with all versions of windows ? Even if I don't install MSPaint or similar tools ?

    Edit: Nevermind. Just found it's documentation.
    http://msdn.microsoft.com/library/de...pathexists.asp
    Last edited by iPrank; Dec 4th, 2005 at 09:28 AM.

  5. #5
    Hyperactive Member umilmi81's Avatar
    Join Date
    Sep 2005
    Location
    Sterling Heights, Mi.
    Posts
    335

    Re: Create multiple subdirectories

    You should really just check and create each directory in code
    VB Code:
    1. Dim fsObj as FileSystemObject
    2. Set fsObj = New FileSystemObject
    3.  
    4. For i = 0 to UBound(Arr1)
    5.     If Not fsObj.FolderExists(BaseDir & "\" & Arr1(i)) Then fsObj.CreateFolder(BaseDir & "\" & Arr1(i))
    6.     For j = 0 to UBound(Arr2)
    7.        If Not fsObj.FolderExists(BaseDir & "\" & Arr1(i)) Then fsObj.CreateFolder(BaseDir & "\" & Arr1(i) & "\" & Arr2(j))
    8.        For k = 0 to UBound(Arr3)
    9.            If Not fsObj.FolderExists(BaseDir & "\" & Arr1(i)) Then fsObj.CreateFolder(BaseDir & "\" & Arr1(i) & "\" & Arr2(j) & "\" & Arr3(k))
    10.        Next k
    11.     Next j
    12. Next i
    13. Set fsObj = Nothing

  6. #6

  7. #7
    Hyperactive Member umilmi81's Avatar
    Join Date
    Sep 2005
    Location
    Sterling Heights, Mi.
    Posts
    335

    Re: Create multiple subdirectories

    Quote Originally Posted by RhinoBull
    Why the heck should we ???
    Because:
    A) It's not that hard
    B) It does't require including any non-activeX Dll's
    C) That's how you do it every other programming language

  8. #8
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Create multiple subdirectories

    Quote Originally Posted by umilmi81
    Because:
    A) It's not that hard
    No, it's not but very redundant.

    Quote Originally Posted by umilmi81
    Because:
    B) It does't require including any non-activeX Dll's
    It's a standard windows component since W2K and prior to that it was just another dll.

    Quote Originally Posted by umilmi81
    Because:
    C) That's how you do it every other programming language
    Really? Never new that every other language would benefit from looping rather than single line call.

  9. #9
    Hyperactive Member umilmi81's Avatar
    Join Date
    Sep 2005
    Location
    Sterling Heights, Mi.
    Posts
    335

    Re: Create multiple subdirectories

    Quote Originally Posted by RhinoBull
    Really? Never new that every other language would benefit from looping rather than single line call.
    Name a language that automatically creates subdirectories for you. Perhaps the .NET file system object has an additional flag for this behavior. But I've never encountered one.

    I'm just saying, it's a good practice to get into because it's just the way the paradigm works.

  10. #10
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Create multiple subdirectories

    My friend - what are you talking about ??? You're writing your own program and there is an OS major component available for you so all you have to do is make a single call to one of its functions - that's all. If you wish not to than it's your decision and I wouldn't want to be part of it. What do you care how it is done in the C DLL - you should care more about performance and results and there is no way that VB6 can compete with C when it comes to string and/or directories structure parsing.

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