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

后端 未结 12 1353
孤独总比滥情好
孤独总比滥情好 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条回答
  •  猫巷女王i
    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
    

提交回复
热议问题