Results 1 to 10 of 10

Thread: Make Dir and Sub Dir

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    111

    Make Dir and Sub Dir

    I need to create 2 new directories of of which are acctual sub directories of a Sub directory that already exist.

    MAIN App.Path
    --------|
    --------|--sub---->210
    -----------------------|
    -----------------------|--sub--->strYear Dir
    ----------------------------------------|
    ----------------------------------------|--sub-------->strMonth Dir

    The last 2 Dir's above directories as explaind in the code below would be created within this directory "210"



    VB Code:
    1. Dim Confirm As String
    2. Dim strYear As String
    3. Dim strMOnth As String
    4.  
    5.  strYear = Format(DTP.Value, "yyyy")
    6.  strMonth = FOrmat(DTP.Value, "MMMM")
    7.  
    8. 'Psuedo Code -as I am not sure here what to do but something like this
    9. ' Check if a Dir exist in a Dir named 210 in Main App.Path
    10.  
    11. If Dir does Not Exist Then
    12.  
    13.   Confirm = MsgBox("Do you want to create Dir for " & strYear & "?", vbQuestion + vbYesNo)
    14.    If Confirm = vbYes Then
    15.     MkDir-> strYear ' strYear Dir is a sub Dir of a Sub Dir residing in the Main App.Path as shown on next line
    16.     ' Main App. Path
    17.         '210 <---This is the DIrectory the strYear directory will be created in
    18.         MakeSubDir-> strMonth ' This is Sub Dir to strYear Dir
    19.      Else
    20.      Exit Sub
    21.     End If
    22. ElseIf Dir does Exist Then
    23.  
    24.   'Check to see if  strMonth Dir exist in strYear dir if not then create it
    25.   If strMonth Dir does Not Exist Then
    26.    
    27.    Confirm = MsgBox(" wanna Make it blah blah", vbQuestion + vbYesNo)
    28.     If COnfirm = vbYes Then
    29.  
    30.       MkDIr strMonth ' This is Sub of strYear Dir just created
    31.      Else
    32.       Exit Sub
    33.     End If
    34.  
    35. ' If all is there or created then I will save files to strMonth Dir
    Help appreciated very much
    vbMarkO

  2. #2
    Addicted Member
    Join Date
    Jan 2003
    Posts
    163
    one possible solution is to use the CreateFolder method of the FileSystemObject

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Try this

    VB Code:
    1. Dim Confirm As String
    2. Dim strYear As String
    3. Dim strMOnth As String
    4.  
    5.  strYear = Format(DTP.Value, "yyyy")
    6.  strMonth = FOrmat(DTP.Value, "MMMM")
    7.  
    8. ' Check if a Dir exist in a Dir named 210 in Main App.Path
    9.  
    10. If Dir(app.path & "\210\" & strYear,vbDirectory) = "" Then
    11.   If = MsgBox("Do you want to create Dir for " & strYear & "?", vbQuestion + vbYesNo) = vbYes Then
    12.      MkDir app.path & "\210\" & strYear
    13.   Else
    14.      Exit Sub
    15.   End If
    16. End if
    17.  
    18. If Dir(app.path & "\210\" & strYear & "\" & strMonth,vbDirectory) = "" Then
    19.  
    20.   'Check to see if  strMonth Dir exist in strYear dir if not then create it
    21.    If = MsgBox(" wanna Make it blah blah", vbQuestion + vbYesNo) = vbYes then
    22.       MkDIr app.path & "\210\" & strYear & "\" & strMonth
    23.    End If
    24. End if

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    This might help :

    VB Code:
    1. Private Function FolderExists(sFolder As String) As Boolean
    2.     If Len(Trim$(Dir$(sFolder, vbDirectory))) Then
    3.         FolderExists = True
    4.     End If
    5. End Function


    Has someone helped you? Then you can Rate their helpful post.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    111
    Originally posted by brucevde
    Try this

    VB Code:
    1. Dim Confirm As String
    2. Dim strYear As String
    3. Dim strMOnth As String
    4.  
    5.  strYear = Format(DTP.Value, "yyyy")
    6.  strMonth = FOrmat(DTP.Value, "MMMM")
    7.  
    8. ' Check if a Dir exist in a Dir named 210 in Main App.Path
    9.  
    10. If Dir(app.path & "\210\" & strYear,vbDirectory) = "" Then
    11.   If = MsgBox("Do you want to create Dir for " & strYear & "?", vbQuestion + vbYesNo) = vbYes Then
    12.      MkDir app.path & "\210\" & strYear
    13.   Else
    14.      Exit Sub
    15.   End If
    16. End if
    17.  
    18. If Dir(app.path & "\210\" & strYear & "\" & strMonth,vbDirectory) = "" Then
    19.  
    20.   'Check to see if  strMonth Dir exist in strYear dir if not then create it
    21.    If = MsgBox(" wanna Make it blah blah", vbQuestion + vbYesNo) = vbYes then
    22.       MkDIr app.path & "\210\" & strYear & "\" & strMonth
    23.    End If
    24. End if

    Thank You... I will put this in my Library for refference ... till I get it down... but this works great thanx again

    vbMarkO

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    111
    Originally posted by manavo11
    This might help :

    VB Code:
    1. Private Function FolderExists(sFolder As String) As Boolean
    2.     If Len(Trim$(Dir$(sFolder, vbDirectory))) Then
    3.         FolderExists = True
    4.     End If
    5. End Function

    Hmmm This looks interesting... How would I aim this so that its searching for the directories I mentioned in my code

    strYear Dir and strMonth Dir

    Is sFolder where I would place strYear?
    like this
    VB Code:
    1. Dim strYear As String
    2. strYear = Format(DTP.Value, "yyyy")
    3.  
    4. Private Function FolderExists(strYear As String) As Boolean
    5.     If Len(Trim$(Dir$(strYear, vbDirectory))) Then
    6.         FolderExists = True
    7.     End If
    8. End Function
    9.  ' OR Like this
    10. Private Function FolderExists(strYear As String) As Boolean
    11.    strYear = Format(DTP.Value, "yyyy")
    12.     If Len(Trim$(Dir$(strYear, vbDirectory))) Then
    13.         FolderExists = True
    14.     End If
    15. End Function

    Like that???
    vbMarkO
    Last edited by vbMarkO; Feb 12th, 2004 at 05:55 PM.

  7. #7
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    I was thinking that you can have the function the same always as I posted it and change the sFolder that you pass

    Like :

    VB Code:
    1. MsgBox FolderExists(App.Path & "\" & strYear)


    Has someone helped you? Then you can Rate their helpful post.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    111
    Originally posted by manavo11
    I was thinking that you can have the function the same always as I posted it and change the sFolder that you pass

    Like :

    VB Code:
    1. MsgBox FolderExists(App.Path & "\" & strYear)
    CHange sFOlder that you Pass?

    Not sure what You mean... Didnt I do that?

    VB Code:
    1. Private Function FolderExists(sFolder As String) As Boolean ' Do I leave sFolder here or change it to strYear???????
    2.     If Len(Trim$(Dir$(sFolder, vbDirectory))) Then ' Do I leave SFolder here or make it strYear????????
    3.       MsgBox FolderExists(App.Path & "\" & strYear)
    4.     End If
    5. End Function

    IS this what you mean???

    vbMarkO

  9. #9
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    I haven't tested this but...

    VB Code:
    1. Private Function FolderExists(sFolder As String) As Boolean
    2.     If Len(Trim$(Dir$(sFolder, vbDirectory))) Then
    3.         FolderExists = True
    4.     End If
    5. End Function


    VB Code:
    1. Dim Confirm As String
    2. Dim strYear As String
    3. Dim strMOnth As String
    4.  
    5.  strYear = Format(DTP.Value, "yyyy")
    6.  strMonth = FOrmat(DTP.Value, "MMMM")
    7.  
    8. 'Psuedo Code -as I am not sure here what to do but something like this
    9. ' Check if a Dir exist in a Dir named 210 in Main App.Path
    10.  
    11. If FolderExists(App.Path & "\210") = False Then
    12.  
    13.   Confirm = MsgBox("Do you want to create Dir for " & strYear & "?", vbQuestion + vbYesNo)
    14.    If Confirm = vbYes Then
    15.     MkDir App.Path & "\210\" & strYear
    16.     MkDir App.Path & "\210\" & strYear & "\" & strMonth
    17.    Else
    18.      Exit Sub
    19.    End If
    20. ElseIf Dir does Exist Then
    21.  
    22.   'Check to see if  strMonth Dir exist in strYear dir if not then create it
    23.   If FolderExists(App.Path & "\210\" & strYear & "\" & strMonth) =False Then
    24.    
    25.    Confirm = MsgBox(" wanna Make it blah blah", vbQuestion + vbYesNo)
    26.     If COnfirm = vbYes Then
    27.  
    28.       MkDir App.Path & "\210\" & strYear & "\" &      Else
    29.       Exit Sub
    30.     End If

    Maybe something like this?


    Has someone helped you? Then you can Rate their helpful post.

  10. #10
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431
    Here's an archived article from Karl Moore's poor old vbworld (weeps): http://web.archive.org/web/200201241...es/tip528.html

    It uses the MakeSureDirectoryPathExists API to automate creation of any and all subdirectories. Nicely useful, just like the old site (weeps again)...
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

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