LumpoDelMagnifico
Electrical
- Sep 22, 2004
- 35
OK, I am trying to use a Dir function to create nested sub directories to store my drawings in. I create an array containing all the positions of "/" in my directory path. then I use Mkdir to create the sub directories using the following code
i = 0
While i < length
If Place(i) < 4 Then GoTo Skip
MyDir = Left(Directory, Place(i))
If Dir(MyDir) = "" Then
MkDir MyDir
End If
Skip:
i = i + 1
Wend
[COLOR=/blue]
This works fine if the whole directory path doesnt exist. but, if the first part of the directory structure exists, then the Dir(Mydir) returns "" even when I know the directory exists. Then Mkdir tries to create the directory and it throws an error. Can anyone help me figure out what I am doing wrong. Here is the full subroutine that I am using.
Sub CreateDirectory(Directory As String)
Dim Place() As Integer
Dim i, j, length As Integer
Dim MyDir As String
i = 0
j = 0
length = Len(Directory)
If Dir(Directory) <> "" Then Exit Sub
Loop1:
i = InStr(i + 1, Directory, "/")
If i = j Or i = 0 Then
GoTo DoneFinding
Else
DarrayAdd Place, i
j = i
GoTo Loop1
End If
DoneFinding:
length = UBound(Place)
i = 0
While i < length
If Place(i) < 4 Then GoTo Skip
MyDir = Left(Directory, Place(i))
If Dir(MyDir) = "" Then
MkDir MyDir
End If
Skip:
i = i + 1
Wend
End Sub
[COLOR=/blue]
And here is the Immediate call I am having trouble with
CreateDirectory "C:/Stddwgs/MyDrawings/Stuff/Mystuff/1/"
[COLOR=/blue]
Any ideas would be greatly appreciated.
i = 0
While i < length
If Place(i) < 4 Then GoTo Skip
MyDir = Left(Directory, Place(i))
If Dir(MyDir) = "" Then
MkDir MyDir
End If
Skip:
i = i + 1
Wend
[COLOR=/blue]
This works fine if the whole directory path doesnt exist. but, if the first part of the directory structure exists, then the Dir(Mydir) returns "" even when I know the directory exists. Then Mkdir tries to create the directory and it throws an error. Can anyone help me figure out what I am doing wrong. Here is the full subroutine that I am using.
Sub CreateDirectory(Directory As String)
Dim Place() As Integer
Dim i, j, length As Integer
Dim MyDir As String
i = 0
j = 0
length = Len(Directory)
If Dir(Directory) <> "" Then Exit Sub
Loop1:
i = InStr(i + 1, Directory, "/")
If i = j Or i = 0 Then
GoTo DoneFinding
Else
DarrayAdd Place, i
j = i
GoTo Loop1
End If
DoneFinding:
length = UBound(Place)
i = 0
While i < length
If Place(i) < 4 Then GoTo Skip
MyDir = Left(Directory, Place(i))
If Dir(MyDir) = "" Then
MkDir MyDir
End If
Skip:
i = i + 1
Wend
End Sub
[COLOR=/blue]
And here is the Immediate call I am having trouble with
CreateDirectory "C:/Stddwgs/MyDrawings/Stuff/Mystuff/1/"
[COLOR=/blue]
Any ideas would be greatly appreciated.