Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Apr 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating a nested directory tree (Office 97)

    I have a created a utility to take all word files in a folder and print them to postscript - in preparation for going to PDF elsewhere. There is an option to print out all files in nested folders under the main source folder. Files are printed out to a destination folder.

    The problem is that the destination folder doesn't have the same nested structure. So I need to create the folders before a printtofile will work.

    I can create the first level easily eg: c:my documentshere

    But, I can't create a two level directory (eg c:my documentsheretest1) unless the first level folder exists. I can't figure out how to test which folders exist higher in the tree before creating the lower level folders.

    I've tried error trapping but I get errors within error trapped processing so, the second errors aren't trapped.

    I've attached a word file with the code.

    All very confusing but, can anyone help ?
    Attached Files Attached Files
    <img src=/S/flags/Australia.gif border=0 alt=Australia width=30 height=18>

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Creating a nested directory tree (Office 97)

    In Office97, you do not have the benefit of the Split function, so...

    You can use Dir(path) to try to confirm the presence of a folder, and march through your path with InStr(). For example:
    <pre>Sub FolderTest()
    Dim strFullPath As String, strTestPath As String
    Dim intStart As Integer, intBSlash As Integer
    strFullPath = "c:level1level2level3"

    intStart = 4 'start after the drive designation

    Do
    'determine location of "next" backslash in path
    intBSlash = InStr(intStart, strFullPath, "")
    If intBSlash = Len(strFullPath) Then
    'terminal , should be ignored
    Exit Do
    ElseIf intBSlash = 0 Then
    'remainder of string is last level
    strTestPath = strFullPath
    Else
    'extract path to intermediate folder level
    strTestPath = Left(strFullPath, intBSlash - 1)
    End If
    'test for existence of folder and create if desired
    If Dir(strTestPath, vbDirectory) = vbNullString Then
    If MsgBox("Folder " & strTestPath & " was not found. Create it?", _
    vbQuestion + vbYesNo) = vbYes Then
    MkDir strTestPath
    Else
    Exit Do 'proceeding will result in an error
    End If
    End If
    'exit if we have exhausted the full path string
    If Len(strTestPath) >= Len(strFullPath) - 1 Then Exit Do
    'otherwise, reset the search starting position and loop
    intStart = Len(strTestPath) + 2
    Loop
    MsgBox "Done!"
    End Sub</pre>

    Hope this helps.

  3. #3
    Lounger
    Join Date
    Apr 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating a nested directory tree (Office 97)

    Jefferson, add another notch to your WMVP status ! This works a treat.

    I've put your code in to run when my routine finds a document that's in a source folder that doesn't exist at the destination. So, it executes only when needed. It runs as quick as a flash too !

    Many thanks.
    <img src=/S/flags/Australia.gif border=0 alt=Australia width=30 height=18>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •