Link to home
Start Free TrialLog in
Avatar of chrisryhal
chrisryhal

asked on

Create Folder If Non Already There

The attached code copies my file to a location just fine.  I get an error though if the folder is not already there.  So, in this code case if the folder "BAQ" is not there, can we create it?
Dim sSource As String = lblAddFile.Text
        Dim sDest As String = strFileRepository & "BAQ\" & strBAQFileName
 
        If System.IO.File.Exists(sDest) Then
            If MsgBox("There Is Already A BAQ With That Name.  Overwrite?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
                System.IO.File.Copy(sSource, sDest, True)
            End If
        Else
            System.IO.File.Copy(sSource, sDest)
        End If

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ee_rlee
ee_rlee
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Joel Coehoorn
Just call this:
    CreateFolder(strFileRepository & "BAQ\)
Sub CreateFolder(ByVal FolderNameAndPath As String)
    If Not IO.Directory.Exists(FolderNameAndPath) Then
        IO.Directory.Create(FolderNameAndPath)
    End If
End Sub

Open in new window