|
-
Feb 12th, 2004, 04:50 PM
#1
Thread Starter
Lively Member
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:
Dim Confirm As String
Dim strYear As String
Dim strMOnth As String
strYear = Format(DTP.Value, "yyyy")
strMonth = FOrmat(DTP.Value, "MMMM")
'Psuedo Code -as I am not sure here what to do but something like this
' Check if a Dir exist in a Dir named 210 in Main App.Path
If Dir does Not Exist Then
Confirm = MsgBox("Do you want to create Dir for " & strYear & "?", vbQuestion + vbYesNo)
If Confirm = vbYes Then
MkDir-> strYear ' strYear Dir is a sub Dir of a Sub Dir residing in the Main App.Path as shown on next line
' Main App. Path
'210 <---This is the DIrectory the strYear directory will be created in
MakeSubDir-> strMonth ' This is Sub Dir to strYear Dir
Else
Exit Sub
End If
ElseIf Dir does Exist Then
'Check to see if strMonth Dir exist in strYear dir if not then create it
If strMonth Dir does Not Exist Then
Confirm = MsgBox(" wanna Make it blah blah", vbQuestion + vbYesNo)
If COnfirm = vbYes Then
MkDIr strMonth ' This is Sub of strYear Dir just created
Else
Exit Sub
End If
' If all is there or created then I will save files to strMonth Dir
Help appreciated very much
vbMarkO
-
Feb 12th, 2004, 04:56 PM
#2
Addicted Member
one possible solution is to use the CreateFolder method of the FileSystemObject
-
Feb 12th, 2004, 04:59 PM
#3
Try this
VB Code:
Dim Confirm As String
Dim strYear As String
Dim strMOnth As String
strYear = Format(DTP.Value, "yyyy")
strMonth = FOrmat(DTP.Value, "MMMM")
' Check if a Dir exist in a Dir named 210 in Main App.Path
If Dir(app.path & "\210\" & strYear,vbDirectory) = "" Then
If = MsgBox("Do you want to create Dir for " & strYear & "?", vbQuestion + vbYesNo) = vbYes Then
MkDir app.path & "\210\" & strYear
Else
Exit Sub
End If
End if
If Dir(app.path & "\210\" & strYear & "\" & strMonth,vbDirectory) = "" Then
'Check to see if strMonth Dir exist in strYear dir if not then create it
If = MsgBox(" wanna Make it blah blah", vbQuestion + vbYesNo) = vbYes then
MkDIr app.path & "\210\" & strYear & "\" & strMonth
End If
End if
-
Feb 12th, 2004, 05:06 PM
#4
This might help :
VB Code:
Private Function FolderExists(sFolder As String) As Boolean
If Len(Trim$(Dir$(sFolder, vbDirectory))) Then
FolderExists = True
End If
End Function
Has someone helped you? Then you can Rate their helpful post. 
-
Feb 12th, 2004, 05:45 PM
#5
Thread Starter
Lively Member
Originally posted by brucevde
Try this
VB Code:
Dim Confirm As String
Dim strYear As String
Dim strMOnth As String
strYear = Format(DTP.Value, "yyyy")
strMonth = FOrmat(DTP.Value, "MMMM")
' Check if a Dir exist in a Dir named 210 in Main App.Path
If Dir(app.path & "\210\" & strYear,vbDirectory) = "" Then
If = MsgBox("Do you want to create Dir for " & strYear & "?", vbQuestion + vbYesNo) = vbYes Then
MkDir app.path & "\210\" & strYear
Else
Exit Sub
End If
End if
If Dir(app.path & "\210\" & strYear & "\" & strMonth,vbDirectory) = "" Then
'Check to see if strMonth Dir exist in strYear dir if not then create it
If = MsgBox(" wanna Make it blah blah", vbQuestion + vbYesNo) = vbYes then
MkDIr app.path & "\210\" & strYear & "\" & strMonth
End If
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
-
Feb 12th, 2004, 05:48 PM
#6
Thread Starter
Lively Member
Originally posted by manavo11
This might help :
VB Code:
Private Function FolderExists(sFolder As String) As Boolean
If Len(Trim$(Dir$(sFolder, vbDirectory))) Then
FolderExists = True
End If
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:
Dim strYear As String
strYear = Format(DTP.Value, "yyyy")
Private Function FolderExists(strYear As String) As Boolean
If Len(Trim$(Dir$(strYear, vbDirectory))) Then
FolderExists = True
End If
End Function
' OR Like this
Private Function FolderExists(strYear As String) As Boolean
strYear = Format(DTP.Value, "yyyy")
If Len(Trim$(Dir$(strYear, vbDirectory))) Then
FolderExists = True
End If
End Function
Like that???
vbMarkO
Last edited by vbMarkO; Feb 12th, 2004 at 05:55 PM.
-
Feb 12th, 2004, 06:27 PM
#7
-
Feb 12th, 2004, 08:19 PM
#8
Thread Starter
Lively Member
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:
MsgBox FolderExists(App.Path & "\" & strYear)
CHange sFOlder that you Pass?
Not sure what You mean... Didnt I do that?
VB Code:
Private Function FolderExists(sFolder As String) As Boolean ' Do I leave sFolder here or change it to strYear???????
If Len(Trim$(Dir$(sFolder, vbDirectory))) Then ' Do I leave SFolder here or make it strYear????????
MsgBox FolderExists(App.Path & "\" & strYear)
End If
End Function
IS this what you mean???
vbMarkO
-
Feb 15th, 2004, 04:19 PM
#9
I haven't tested this but...
VB Code:
Private Function FolderExists(sFolder As String) As Boolean
If Len(Trim$(Dir$(sFolder, vbDirectory))) Then
FolderExists = True
End If
End Function
VB Code:
Dim Confirm As String
Dim strYear As String
Dim strMOnth As String
strYear = Format(DTP.Value, "yyyy")
strMonth = FOrmat(DTP.Value, "MMMM")
'Psuedo Code -as I am not sure here what to do but something like this
' Check if a Dir exist in a Dir named 210 in Main App.Path
If FolderExists(App.Path & "\210") = False Then
Confirm = MsgBox("Do you want to create Dir for " & strYear & "?", vbQuestion + vbYesNo)
If Confirm = vbYes Then
MkDir App.Path & "\210\" & strYear
MkDir App.Path & "\210\" & strYear & "\" & strMonth
Else
Exit Sub
End If
ElseIf Dir does Exist Then
'Check to see if strMonth Dir exist in strYear dir if not then create it
If FolderExists(App.Path & "\210\" & strYear & "\" & strMonth) =False Then
Confirm = MsgBox(" wanna Make it blah blah", vbQuestion + vbYesNo)
If COnfirm = vbYes Then
MkDir App.Path & "\210\" & strYear & "\" & Else
Exit Sub
End If
Maybe something like this?
Has someone helped you? Then you can Rate their helpful post. 
-
Feb 15th, 2004, 04:37 PM
#10
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|