paulcat
10-04-2001, 09:39 PM
I have a frmBrowseDirectory, basically, it browse the location of certain folders where the users want to install the software. Of course, I want them to have a functionality to create a folder after they browsed to a drive, they can type in a folder. The following code checks if the folder/directory exists, if not, it creates it. However, it only creates one folder. Example, drive is C:\ and the user typed in C:\MyStuff\Hello, the code stops because there is another folder inside MyStuff folder. It works fine if only MyStuff needs to be created but of course, the users should have the ability to create a folder within a folder. Here is the code
If Dir$(Me.Location, vbDirectory) <> "" Then
'do nothing
Else
If MsgBox("The directory doesnt exist, do you want to create it?", vbYesNo + vbQuestion, "Create Directory") = vbYes Then
Set fsO = CreateObject("Scripting.filesystemObject")
' Create the directory
Set oDirectory = fsO.CreateFolder(Me.Location)
' Establish it as a container of folder objects
'Set oFolders = oDirectory.SubFolders
' Add a sub directory to MyDirectory without mentionning it's location!
' Set oSubDir = oFolders.Add("SubDirectory")
End If
End If
----------------------------------------------------------
The lines of code below checks if the user accepts the default location where the software will be installed C:\Program Files\Hello. However, I cant figure out how I can create a folder called Hello inside a folder Program Files without having to create "Program Files" folder and overwrite the current one. Right now, the code fails because "Program Files" folder exists already.
'gLocation is a global variable that holds a location
If gLocation = "C:\Program Files\Hello" Then
If Dir$(gLocation, vbDirectory) <> "" Then
'do nothing
Else
Set fsO = CreateObject("Scripting.filesystemObject")
' Create the directory
Set oDirectory = fsO.CreateFolder("C:\Program Files")
' Establish it as a container of folder objects
Set oFolders = oDirectory.SubFolders
' Add a sub directory to MyDirectory without mentionning it's location!
Set oSubDir = oFolders.Add("Hello")
End If
End If
If Dir$(Me.Location, vbDirectory) <> "" Then
'do nothing
Else
If MsgBox("The directory doesnt exist, do you want to create it?", vbYesNo + vbQuestion, "Create Directory") = vbYes Then
Set fsO = CreateObject("Scripting.filesystemObject")
' Create the directory
Set oDirectory = fsO.CreateFolder(Me.Location)
' Establish it as a container of folder objects
'Set oFolders = oDirectory.SubFolders
' Add a sub directory to MyDirectory without mentionning it's location!
' Set oSubDir = oFolders.Add("SubDirectory")
End If
End If
----------------------------------------------------------
The lines of code below checks if the user accepts the default location where the software will be installed C:\Program Files\Hello. However, I cant figure out how I can create a folder called Hello inside a folder Program Files without having to create "Program Files" folder and overwrite the current one. Right now, the code fails because "Program Files" folder exists already.
'gLocation is a global variable that holds a location
If gLocation = "C:\Program Files\Hello" Then
If Dir$(gLocation, vbDirectory) <> "" Then
'do nothing
Else
Set fsO = CreateObject("Scripting.filesystemObject")
' Create the directory
Set oDirectory = fsO.CreateFolder("C:\Program Files")
' Establish it as a container of folder objects
Set oFolders = oDirectory.SubFolders
' Add a sub directory to MyDirectory without mentionning it's location!
Set oSubDir = oFolders.Add("Hello")
End If
End If