How do I create a folder in VB if it doesn't exist?

后端 未结 12 1283
孤独总比滥情好
孤独总比滥情好 2020-12-23 11:29

I wrote myself a little downloading application so that I could easily grab a set of files from my server and put them all onto a new pc with a clean install of Windows, wi

相关标签:
12条回答
  • 2020-12-23 11:48
    If(Not System.IO.Directory.Exists(YourPath)) Then
        System.IO.Directory.CreateDirectory(YourPath)
    End If
    
    0 讨论(0)
  • 2020-12-23 11:50

    (imports System.IO)

    if Not Directory.Exists(Path) then
      Directory.CreateDirectory(Path)
    end if
    0 讨论(0)
  • 2020-12-23 11:51

    VB.NET? System.IO.Directory.Exists(string path)

    0 讨论(0)
  • 2020-12-23 11:53

    Under System.IO, there is a class called Directory. Do the following:

    If Not Directory.Exists(path) Then
        Directory.CreateDirectory(path)
    End If
    

    It will ensure that the directory is there.

    0 讨论(0)
  • 2020-12-23 11:53

    I see how this would work, what would be the process to create a dialog box that allows the user name the folder and place it where you want to.

    Cheers

    0 讨论(0)
  • 2020-12-23 11:54

    Try the System.IO.DirectoryInfo class.

    The sample from MSDN:

    Imports System
    Imports System.IO
    
    Public Class Test
        Public Shared Sub Main()
            ' Specify the directories you want to manipulate.
            Dim di As DirectoryInfo = New DirectoryInfo("c:\MyDir")
            Try
                ' Determine whether the directory exists.
                If di.Exists Then
                    ' Indicate that it already exists.
                    Console.WriteLine("That path exists already.")
                    Return
                End If
    
                ' Try to create the directory.
                di.Create()
                Console.WriteLine("The directory was created successfully.")
    
                ' Delete the directory.
                di.Delete()
                Console.WriteLine("The directory was deleted successfully.")
    
            Catch e As Exception
                Console.WriteLine("The process failed: {0}", e.ToString())
            End Try
        End Sub
    End Class
    
    0 讨论(0)
提交回复
热议问题