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

后端 未结 12 1329
孤独总比滥情好
孤独总比滥情好 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 12:06

    Just do this:

            Dim sPath As String = "Folder path here"
        If (My.Computer.FileSystem.DirectoryExists(sPath) = False) Then
            My.Computer.FileSystem.CreateDirectory(sPath + "/")
        Else
            'Something else happens, because the folder exists
        End If
    

    I declared the folder path as a String (sPath) so that way if you do use it multiple times it can be changed easily but also it can be changed through the program itself.

    Hope it helps!

    -nfell2009

提交回复
热议问题