×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Dir(Mydir) Problem

Dir(Mydir) Problem

Dir(Mydir) Problem

(OP)
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
[color blue]
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.
[color blue]
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
[color blue]
CreateDirectory "C:/Stddwgs/MyDrawings/Stuff/Mystuff/1/"
[color /blue]
Any ideas would be greatly appreciated.

RE: Dir(Mydir) Problem

(OP)
Actually, I already figured it out. But this will save me several lines of code. I always have to do things the hard way. Thanks Borg.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources