Hi,
I am NOW doing a short application that installs a program, without the program being embedded into the application.
I have found myself at a loss for code, now that I cannont figure out how I can COPY the entire contents of a folder to a new folder, WITHOUT 'deleting' the contents of the original folder.
So far, I have used variables and environmentpaths to create the folder connection, however, I still cnnot do any thing without the code.
Anybody out there have any ideas?

See if this helps.
1 Button

Public Class Form1
    Private sTemp1, sTemp2 As String

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        sTemp1 = "" : sTemp2 = ""
        Dim fbd As New FolderBrowserDialog
        With fbd
            .Description = "Select a folder to copy the content FROM..."
            If .ShowDialog = Windows.Forms.DialogResult.OK Then
                sTemp1 = .SelectedPath
            End If
            .Description = "Select a folder to copy the content TO..."
            If .ShowDialog = Windows.Forms.DialogResult.OK Then
                sTemp2 = .SelectedPath
            End If
            If Not sTemp1 = "" OrElse Not sTemp2 = "" Then copyDirectory(sTemp1, sTemp2)
        End With
    End Sub

    Private Sub copyDirectory(ByVal selTargetPath As String, ByVal selDestinationPath As String)
        sTemp1 = ""
        If Not IO.Directory.Exists(selDestinationPath) Then IO.Directory.CreateDirectory(selDestinationPath)
        For Each myCoolFile As String In My.Computer.FileSystem.GetFiles _
                                                 (selTargetPath, FileIO.SearchOption.SearchTopLevelOnly, "*.*")
            sTemp1 = selDestinationPath & "\" & IO.Path.GetFileName(myCoolFile)
            If Not IO.File.Exists(sTemp1) Then
                IO.File.Copy(myCoolFile, sTemp1)
            Else
                MsgBox("File.Exists, cannot copy." & vbNewLine & sTemp1, MsgBoxStyle.Information)
            End If
        Next
        MsgBox(".done.", MsgBoxStyle.Information)
    End Sub
End Class

Thank you for your response codeorder, but that would only deal with the files in the first folder?
The program I would be installing as several sub-directories, so if I were to change the FileIO.SearchOption.SearchTopLevelOnly to a different method, if a method at all, would it obtain files and directories in lower levels as well?
Or should I just use your copy directory script as a function and go the long way listing folder by folder by folder?

Maybe that is what your are looking for:

my.Computer.FileSystem.CopyDirectory("sourceDir", "destinationDir",false)

@GeekByChoice
So this would copy the contents of the folder? Or would it just copy the entire folder?

what do you mean with "it doesn't show up"?
The "My" namespace should be in express available as well.

Sorry, i typed it in wrong... XD

@GeekByChoice
So this would copy the contents of the folder? Or would it just copy the entire folder?

You might read HERE for more detailed information.
If this solved your problem, mark this thread as solved please.

Thank you codeorder and GeekByChoiCe for your codes, they should work quite well.

>>Or should I just use your copy directory script as a function and go the long way listing folder by folder by folder?
.w/the code I posted, you should be able to add file.countBySelCoolFileExtension(".vb",".etc") /overwrite.file methods/and whatever else your little heart desires.:D
.hope it helped more than just copying a directory.over. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.