CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1
    Join Date
    Aug 2000
    Posts
    1,471

    How to declare Mkdir in vb?

    Thanks for your inputs.

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: How to declare Mkdir in vb?

    If your question is how to create a Folder in VB 6, then the answer would be
    Code:
    MkDir "C:\NewFolder"
    If your question is something else, please explain.

  3. #3
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    1,901

    Re: How to declare Mkdir in vb?

    Often I need to make sure the folder exists (if it doesn't then I need to make it)

    What I do is

    Code:
    On Error Resume Next
    MkDir "C:\NewFolder"
    This way you are guaranteed that the folder will always be there

  4. #4
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: How to declare Mkdir in vb?

    Quote Originally Posted by George1111
    Often I need to make sure the folder exists (if it doesn't then I need to make it)

    What I do is

    Code:
    On Error Resume Next
    MkDir "C:\NewFolder"
    This way you are guaranteed that the folder will always be there
    What happens when there is some other error, say you do not have write permission or the drive is not readable. You are not trapping it with the above code and using the above code you will never know what error actually came. I would prefer checking for the existence of folder in a proper way rather than using the above method.

  5. #5
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    1,901

    Re: How to declare Mkdir in vb?

    Something like ..


    Code:
    If Dir("C:\MyFolder") = "" then
          On Error Goto ErrorMakingFolder
          MkDir("C:\MyFolder)
    End If
    
    'Carry on here as everthing is OK
    
    
    Exit Sub
    
    ErrorMakingFolder:
         Msgbox "Error Making Folder 'MyFolder" - Perhaps your permissions etc are not ......etc  etc.."
        Exit sub

  6. #6
    Join Date
    Aug 2000
    Posts
    1,471

    Re: How to declare Mkdir in vb?

    Thanks for your response! Actually, I meant which dll is Mkdir defined in? Thanks for your inputs.
    Quote Originally Posted by Shuja Ali
    If your question is how to create a Folder in VB 6, then the answer would be
    Code:
    MkDir "C:\NewFolder"
    If your question is something else, please explain.

  7. #7
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: How to declare Mkdir in vb?

    It's built-in as a command in VB6.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  8. #8
    Join Date
    Oct 2006
    Posts
    327

    Re: How to declare Mkdir in vb?

    Hello,

    Just in case the question was not formulated as you meant to :

    1) In VB, MKDir is not a function but a Statement

    2) MKDir VB Statement is acting exactly the same way than the CreateDirectory function of the kernel32 Librfary of the Windows Api.

    3) the CreateDirectory function returns a value geater than 0 if it succeeds.
    If it fails, it returns 0 (and you can then use the GetLastError function to get more information upon the reason(s) for which it failed).

  9. #9
    Join Date
    Apr 2006
    Location
    Kolkata, India
    Posts
    278

    Re: How to declare Mkdir in vb?

    Use Microsoft Scripting Runtime as reference.
    Code:
    Declare fso as new file system object.
    
    if fso.folderexists("Name") =true 'where name is your folder name to be created. or checked
     do  something....
    
    else
    fso.createfolder("Name")

  10. #10
    Join Date
    Oct 2006
    Posts
    327

    Re: How to declare Mkdir in vb?

    Hello,

    Why to make an appli heavier (declaring and using FSO) when VB does it fast and very simply !!!

    Code:
    Private Sub Command1_Click()
      MsgBox IIf(Dir("d:\monoutila\", vbDirectory) <> "", "exists", "does not exist")
    End Sub

  11. #11
    Join Date
    Oct 2006
    Posts
    327

    Re: How to declare Mkdir in vb?

    So that (for our friend's purpose) :

    Code:
    Private Sub Command1_Click()
      mypath = "d:\monoutila"
      checkit = IIf(Dir(mypath & "\", vbDirectory) <> "", True, False)
      If Not checkit Then MkDir mypath
    End Sub

  12. #12
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: How to declare Mkdir in vb?

    Yup, except I would declare and strongly type: "mypath" and "checkit".
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  13. #13
    Join Date
    Oct 2006
    Posts
    327

    Re: How to declare Mkdir in vb?


  14. #14
    Join Date
    Aug 2006
    Posts
    145

    Re: How to declare Mkdir in vb?

    I would recommend using the MakeSureDirectoryPathExists API. It doesn't throw errors if the folder exists and will create any subdirectories that need creating too:
    Code:
    Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" ( _
        ByVal lpPath As String) As Long
    
    Private Sub Command1_Click()
        MakeSureDirectoryPathExists "C:\All\These\Folders\Are\Created\"
    End Sub

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

Featured