Results 1 to 7 of 7

Thread: MkDir Command - how to use with the filename

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384

    MkDir Command - how to use with the filename

    I need to use the MkDir Command when the string contains the required directory to be made and the filename.
    e.g. I want to create a directory 'Directory1'
    Code:
    Dim fileLocation as String
    fileLocation = "C:\Root\Directory1\file1.txt"
    
    MkDir fileLocation
    But I keep getting a Run-time error '76' Path not found. I know this is because I have the filename included in the string. How can I include the filename in the string without running into error?

    Note: The file doesn't have to be created just the directory
    Mel

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    VB Code:
    1. Private Sub someSub()
    2.     Dim fileLocation as String
    3.     fileLocation = "C:\Root\Directory1\file1.txt"
    4.  
    5.     MkDir returnPathOfFile(fileLocation)
    6. End Sub
    7.  
    8. Private Function returnPathOfFile(ByVal strFile As String) As String
    9.     returnPathOfFile = Left(strFile, InStrRev(strFile, "\"))
    10. End Function
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Jamie is always drunk and so I think he misunderstood your question

    You need to Make the directory first and then create files within it. If u want the text in a textbox to be the name of a file or directory just put it outside of the quotes... eg fileLocation = "C:\Root\Directory1\" & text1.text
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  4. #4
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    Re: MkDir Command - how to use with the filename

    Originally posted by mel_flynn
    I want to create a directory 'Directory1'

    Note: The file doesn't have to be created just the directory
    :p
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    Good Stuff! Thanks

    Now, say I want to make multiple directories in the one statement i.e. Directory1 and Directory 2 :
    Code:
    Private Sub someSub()
        Dim fileLocation as String
        fileLocation = "C:\Root\Directory1\Directory2\file1.txt"
        
        MkDir returnPathOfFile(FileLocation)
    End Sub
    
    Private Function returnPathOfFile(ByVal strFile As String) As String
        returnPathOfFile = Left(strFile, InStrRev(strFile, "\"))
    End Function
    I keep getting path not found with MkDir returnPathOfFile(FileLocation). I know this is because both directories don't exist ... so how can I make both??
    Mel

  6. #6
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    You have to make one at a time afaik
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  7. #7
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849
    As plenderj mentioned, you may have to write your own function for creating a nested directory structure. The one I used earlier is available at http://209.120.143.185/showthread.ph...hreadid=186500

    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

Posting Permissions

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



Click Here to Expand Forum to Full Width