0

I already have the code that will copy over any files listed in a listbox but i just need help on how to adapt it to also copy over directories.

Ex. of Listbox

  1. Z:\Test\TestFile.exe
  2. Z:\Test\TestFolder

This is the code i have so far... thank you in advance

For Each item As String In FilesList.Items
    Try
        If IO.File.Exists(item) Then
        My.Computer.FileSystem.CopyFile(item, 
                 FolderChosenText.Text & "\" & IO.Path.GetFileName(item))
        End If
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
Next
Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
  • See [this](http://stackoverflow.com/q/5525573/1070452) and/or [this](http://stackoverflow.com/q/7191677/1070452) and/or [this](http://stackoverflow.com/q/14978894/1070452) or any of 28,000 others from your pal Google – Ňɏssa Pøngjǣrdenlarp Jan 22 '16 at 00:52

2 Answers2

1

You have to use the same logic that you did with files, instead of copying files change it to copy directories. Below is the code:

            If IO.Directory.Exists(item) Then
                My.Computer.FileSystem.CopyDirectory(item,
                FolderChosenText.Text & "\" & IO.Path.GetFileName(item))
            End If
  • Awesome that was too easy. Thank you for your help. Now is there an easy way to track the process with a progress bar? Sorry for my ignorance – Jordan Paris Jan 22 '16 at 03:43
1

You have to assign the minimum and the maximum value for the progress bar control. For instance: 0 as the minimum and the total number of items you have in your ListBox as the maximum. In a loop the progress bar value is going to increase by one until it reaches its maximum. Below is the code:

            ProgressBar1.Minimum = 0
            ProgressBar1.Maximum = FilesList.Items.Count - 1

            For i = 0 To FilesList.Items.Count - 1
                ProgressBar1.Value = i
            Next