Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2002
    Posts
    42

    Unanswered: Creating a Directory and SubDirectory

    When a user exits my application I want them to be able to create a Directory and subdirectory to backup the back end to.
    How do I create say "C:\My_app\backup" using code - if it does not already exist?

  2. #2
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,418
    Provided Answers: 7
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

  3. #3
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    You can also just use the MkDir command.

    MkDir "C:\My_app\"
    MkDir "C:\My_app\backup"

    Then you can use FileCopy.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  4. #4
    Join Date
    Dec 2002
    Posts
    42
    Thanks Star Trekker but it wont create the sub folder.

  5. #5
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    MkDir "C:\My_app\"
    MkDir "C:\My_app\backup\"

    I added a slash.

    If that doesn't work then I would begin to suspect some kind of networking permissions issue. I use this command very often and I have never seen it fail unless the folder already exists or there are permission restrictions at the OS level.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  6. #6
    Join Date
    Dec 2002
    Posts
    42
    Sorry - I wanted to do it all in one go. This will be a text string from the field on my backup form. The user will be asked to type in the folder that they want to back up to. If it doesn't exist then I want my application to be able to create it for them. They might type in "C:\my_app\backup\" or something else containing a subfolder.

  7. #7
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    The VBA MkDir command can't do that, but the CMD one can.

    Shell "cmd /c MkDir ""C:\My_app\backup\"""

    Hmm.... I hope you have the string validated before trying it!
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  8. #8
    Join Date
    Dec 2004
    Location
    Connecticut
    Posts
    85
    I was able to do this with VBA code. Don't ask me where I found the code - probably bits and pieces from the code bank cobbled together with code from other places.

    Code:
     'Check to see if theres a "GPS" folder on drive Y:\
        'If it doesn't exist, create it
        Dim fso
       
        Set fso = CreateObject("Scripting.FileSystemObject")
    
        If (fso.FolderExists("Y:\gps")) Then
    
            ' If the folder exists, do Nothing
            'MsgBox ("The folder already exists")
        
        Else
    
            'Create gps folder in Drive Y:
            fso.CreateFolder ("Y:\gps")
            'MsgBox ("GPS Folder now exists in Drive Y:\")
            
        End If
    This is part of a much larger procedure that I had trouble getting right, so I put in message boxes at each statement to help troubleshooting - that's why they're commented out in the above code. Drive Y is mapped to the user's home directory on the network, so they have all the necessary permissions.

    I assume that once you've created the parrent directory, you can create subdirectories using the same procedure. There may be some DAO or ADO Reference Library that needs to be installed for this to work properly, but I learned long ago to do a "complete" install of Microsoft Office, so they're already on my workstations.

  9. #9
    Join Date
    Dec 2002
    Posts
    42

    Cool

    Thanks Star Trekker that one works fine.

    Haven't tried the suggestion from Trowe - but thanks.

  10. #10
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    You're welcome
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

Posting Permissions

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