Link to home
Start Free TrialLog in
Avatar of CanvasYou
CanvasYou

asked on

How do I copy folders - but only copy newer files over - and have it run on a thread, updating progressbar on main form?

https://www.experts-exchange.com/questions/23829699/Another-Cross-Threading-update-object-question.html
Was my original question - I am not having much luck on here.
Basically:
I want to have some folders copy from one place to another.
Only the files w/ written newer date attribute copy over.
Each time the file copy sub runs - it is on its own thread.
There is 1 main form - the main form has a progress bar that updates as the files are copied..

If anyone understands what I am trying to say - or has a sample of threads updating parent forms - please let me know - its been a few days and no such luck here.
Thanks in Advanced
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America 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 CanvasYou
CanvasYou

ASKER

This is what I meant by write time copy -
See, the folders have some of the same file names there -
so I only want the file name that is newer to copy over.


              If sFile.LastWriteTime > File.GetLastWriteTime(dest & sFile.Name) Then
                        sFile.CopyTo(dest & sFile.Name, True)
                    Else
                        'Invoke label should be here:
                        'Unable to update the form form thread
                        'The refresh does not work either
                        label.Text = "Newer File: " & vbCrLf & sFile.FullName
                        label.Refresh()
                        Me.Refresh()
                    End If

Open in new window

The above code snippet came from the link in my original question above -
file.LastWriteTime is what I wanted to compare by - when copying the files.

2 folders, a source and a destination
it compares the files in source and destination -
and copies the files over that have a newer LastWriteTime

because some of the files will have the same name.
Then this is the only code that will change

   Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, _
            ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        ' Get the parameters sent to the BackgroundWorker
        Dim sourceDirPath As String = e.Argument(0)
        Dim destinationDirPath As String = e.Argument(1)
        ' Get the file information from the source directory
        Dim sourceDirectory As DirectoryInfo = New DirectoryInfo(sourceDirPath)
        Dim sourceFiles() As FileInfo = sourceDirectory.GetFiles()
        ' Get the number of files to copy to the destination directory
        Dim Maximum = sourceFiles.Count.ToString()
        ' Set up progress bar with initial values 
        BackgroundWorker1.ReportProgress(0, Maximum)
 
        For Each fi As FileInfo In sourceFiles
            ' Check to see if Destination file exist 
            If File.Exists(destinationDirPath & "\" & fi.Name) Then
                ' Destination file exist. Check to see if source is newer 
                If fi.LastWriteTime > File.GetLastWriteTime(destinationDirPath & "\" & fi.Name) Then
                    'Source is newer so overwrite the destination file
                    Try
                        ' The last parameter is to overwite an existing file in the destination
                        My.Computer.FileSystem.CopyFile(fi.FullName, destinationDirPath & "\" & fi.Name, True)
                        BackgroundWorker1.ReportProgress(1)
                    Catch ex As Exception
                        ' File may be in use log it to a file so that you can try later
                    End Try
                End If
            Else
                ' Destination file does not exist so just write it
                Try
                    ' The last parameter is to overwite an existing file in the destination
                    My.Computer.FileSystem.CopyFile(fi.FullName, destinationDirPath & "\" & fi.Name, True)
                    BackgroundWorker1.ReportProgress(1)
                Catch ex As Exception
                    ' File may be in use log it to a file so that you can try later
                End Try
            End If
        Next
 
    End Sub

Open in new window

Okay I will try this...
How do I make the Report Progress actually reflect to a form?
For example:
Form1.ProgressBar1.value
?
BackgroundWorker1.ReportProgress(1)

I am still playing with the code you gave me - trying to get it to work.
Thanks - I will let you know.
Thank you - worked out great -
Is there a way that I can have part of the progress - report the file name that is being copied
like have lblFileName.text on main form
and have it change as it copies each file?
and if the file that is being coped over is older than the one that exists in the folder it will just report:
" FILEname was Not copied, newer exists on dest"

Thank you again! for all your help..
Thank you - I posted another sub-question on the forum. If you have time please take a look at it - for me.
Thanks again!
Also - I am trying to copy 64 folders
can I have it start the next folder when the first one finishes?
like when workcomplete - start the next folder?
Hi CanvasYou;

To your question, "How do I make the Report Progress actually reflect to a form?", you would need a reference to the Form1 and then use something like this, MyReference.ProgressBar1.value.

To your question, "Is there a way that I can have part of the progress - report the file name that is being copied like have lblFileName.text on main form". See code sample.

To the question, "Also - I am trying to copy 64 folders can I have it start the next folder when the first one finishes?, like when workcomplete - start the next folder?" Fist, the WorkerCompleted event takes place just before the thread is terminated. In answer to doing all the folders this is what is needed to be done.

The following two lines is from the Button click event:

        Dim params() As Object = {txtSourceDir.Text, txtDestDir.Text}
        BackgroundWorker1.RunWorkerAsync(params)

The params array is where you will place a list of the 64 folders and 64 or 1 destination folder. Then call the BackgroundWorker1 as shown above.

In the BackgroundWorker1 DoWork you will need to parse the array something like this which is in the DoWork:

        Dim sourceDirPath As String = e.Argument(0)
        Dim destinationDirPath As String = e.Argument(1)

Note that e.Argument is the array of objects passed as a parameter to the BackgroundWorker1 in the Button click event. You need to parse it as you constructed it in the Button click event.So for example if you passed in into the first element of params a list of strings, List(Of String), and initialized it with 64 folder names then in the DoWork event you would assign the e.Argument(0) to a variable of List(Of String). Then use a For Each loop to iterate through all the folders and in each folder execute the current code in DoWork to copy the files in the folder to the destination folder.

Fernando



Imports System.IO
 
Public Class Form1
 
    Private Sub FilesCopied_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles btnFileCopied.Click
 
        ' Check to see if directories exist before running
        If Not (Directory.Exists(txtSourceDir.Text) AndAlso Directory.Exists(txtDestDir.Text)) Then
            MessageBox.Show("Directory Source or Destination Does Not Exist. Please Correct", "Directory Not Found")
            Return
        End If
 
        ' Parameters to send to the BackgroundWorker Source & Destination directories
        Dim params() As Object = {txtSourceDir.Text, txtDestDir.Text}
        ' Run the BackgroundWorker
        BackgroundWorker1.RunWorkerAsync(params)
 
 
    End Sub
 
 
    Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, _
            ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        ' Get the parameters sent to the BackgroundWorker
        Dim sourceDirPath As String = e.Argument(0)
        Dim destinationDirPath As String = e.Argument(1)
        ' Get the file information from the source directory
        Dim sourceDirectory As DirectoryInfo = New DirectoryInfo(sourceDirPath)
        Dim sourceFiles() As FileInfo = sourceDirectory.GetFiles()
        ' Get the number of files to copy to the destination directory
        Dim Maximum As Integer = sourceFiles.Count
        ' Set up progress bar with initial values 
        BackgroundWorker1.ReportProgress(0, Maximum)
 
        For Each fi As FileInfo In sourceFiles
            ' Check to see if Destination file exist 
            If File.Exists(destinationDirPath & "\" & fi.Name) Then
                ' Destination file exist. Check to see if source is newer 
                If fi.LastWriteTime > File.GetLastWriteTime(destinationDirPath & "\" & fi.Name) Then
                    'Source is newer so overwrite the destination file
                    Try
                        ' The last parameter is to overwite an existing file in the destination
                        BackgroundWorker1.ReportProgress(1, fi.FullName)
                        My.Computer.FileSystem.CopyFile(fi.FullName, destinationDirPath & "\" & fi.Name, True)
                    Catch ex As Exception
                        ' File may be in use log it to a file so that you can try later
                    End Try
                End If
            Else
                ' Destination file does not exist so just write it
                Try
                    ' The last parameter is to overwite an existing file in the destination
                    BackgroundWorker1.ReportProgress(1, fi.FullName)
                    My.Computer.FileSystem.CopyFile(fi.FullName, destinationDirPath & "\" & fi.Name, True)
                Catch ex As Exception
                    ' File may be in use log it to a file so that you can try later
                End Try
            End If
        Next
 
    End Sub
 
    Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As System.Object, _
            ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
 
        If TypeOf e.UserState Is System.String Then
            Me.lblFileName.Text = e.UserState.ToString()
        Else
            Me.ProgressBar1.Maximum = CType(e.UserState, Integer)
        End If
        ' Update the ProgressBar control
        ProgressBar1.Increment(e.ProgressPercentage)
 
    End Sub
 
    Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, _
            ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
 
        ' Set the ProgressBar to Max is it is not there already
        Me.ProgressBar1.Value = ProgressBar1.Maximum
        Me.lblFileName.Text = "Operation Completed"
 
    End Sub
 
End Class

Open in new window

Thank you!
I am not too familiar with creating a list array.

say I have folder1,folder2,folder3,folder4 ect.

how would I designate that as a list array?

then i have to:



do for each (folder)
     Dim params() As Object = {array items}
        ' Run the BackgroundWorker
        BackgroundWorker1.RunWorkerAsync(params)
loop


I understand the concept but I do not know the mechanics...

I got it to work - but I used 64 If then statements
and a counter
and assigned a number to each folder


I attached the whole thing


Imports System.IO
Public Class frmPhotoCopy02
    Dim source1 As String
    Dim dest1 As String
    Dim source2 As String
    Dim dest2 As String
    Dim source3 As String
    Dim dest3 As String
    Dim source4 As String
    Dim dest4 As String
    Dim CurrentFolder1 As String
    Dim CurrentFolder2 As String
    Dim CurrentFolder3 As String
    Dim CurrentFolder4 As String
 
    Private Sub FilesCopied_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles btnFileCopied.Click
 
        ' Check to see if directories exist before running
        Timer1.Enabled = True
 
        LaunchBGWorker1()
        LaunchBGWorker2()
        LaunchBGWorker3()
        LaunchBGWorker4()
        btnFileCopied.Enabled = False
        lblPleaseWait.Visible = True
 
 
    End Sub
    Private Sub LaunchBGWorker1()
        Me.Refresh()
 
        source1 = lblSource.Text
        dest1 = lblDest.Text
        'source = TextBox1.Text
        'dest = TextBox2.Text
 
 
        If lblCounter1.Text = "0" Then
            CurrentFolder1 = "00"
        End If
        If lblCounter1.Text = "1" Then
            CurrentFolder1 = "01"
        End If
        If lblCounter1.Text = "2" Then
            CurrentFolder1 = "02"
        End If
        If lblCounter1.Text = "3" Then
            CurrentFolder1 = "03"
        End If
        If lblCounter1.Text = "4" Then
            CurrentFolder1 = "04"
        End If
        If lblCounter1.Text = "5" Then
            CurrentFolder1 = "05"
        End If
        If lblCounter1.Text = "6" Then
            CurrentFolder1 = "06"
        End If
        If lblCounter1.Text = "7" Then
            CurrentFolder1 = "07"
        End If
        If lblCounter1.Text = "8" Then
            CurrentFolder1 = "08"
        End If
        If lblCounter1.Text = "9" Then
            CurrentFolder1 = "09"
        End If
        If lblCounter1.Text = "10" Then
            CurrentFolder1 = "10"
        End If
        If lblCounter1.Text = "11" Then
            CurrentFolder1 = "11"
        End If
        If lblCounter1.Text = "12" Then
            CurrentFolder1 = "12"
        End If
        If lblCounter1.Text = "13" Then
            CurrentFolder1 = "13"
        End If
        If lblCounter1.Text = "14" Then
            CurrentFolder1 = "14"
        End If
        If lblCounter1.Text = "15" Then
            CurrentFolder1 = "15"
        End If
        If lblCounter1.Text = "16" Then
            CurrentFolder1 = "16"
        End If
        If lblCounter1.Text = "17" Then
            CurrentFolder1 = "17"
        End If
        If lblCounter1.Text = "18" Then
            CurrentFolder1 = "18"
        End If
        If lblCounter1.Text = "19" Then
            CurrentFolder1 = "19"
        End If
        If lblCounter1.Text = "20" Then
            CurrentFolder1 = "20"
        End If
        If lblCounter1.Text = "21" Then
            CurrentFolder1 = "21"
        End If
        If lblCounter1.Text = "22" Then
            CurrentFolder1 = "22"
        End If
        If lblCounter1.Text = "23" Then
            CurrentFolder1 = "23"
        End If
        If lblCounter1.Text = "24" Then
            CurrentFolder1 = "24"
        End If
        If lblCounter1.Text = "25" Then
            CurrentFolder1 = "25"
        End If
        If lblCounter1.Text = "26" Then
            CurrentFolder1 = "26"
        End If
        If lblCounter1.Text = "27" Then
            CurrentFolder1 = "27"
        End If
        If lblCounter1.Text = "28" Then
            CurrentFolder1 = "28"
        End If
        If lblCounter1.Text = "29" Then
            CurrentFolder1 = "29"
        End If
        If lblCounter1.Text = "30" Then
            CurrentFolder1 = "30"
        End If
        If lblCounter1.Text = "31" Then
            CurrentFolder1 = "31"
        End If
        If lblCounter1.Text = "32" Then
            CurrentFolder1 = "32"
        End If
        If lblCounter1.Text = "33" Then
            CurrentFolder1 = "33"
        End If
        If lblCounter1.Text = "34" Then
            CurrentFolder1 = "34"
        End If
        If lblCounter1.Text = "35" Then
            CurrentFolder1 = "35"
        End If
        If lblCounter1.Text = "36" Then
            CurrentFolder1 = "36"
        End If
        If lblCounter1.Text = "37" Then
            CurrentFolder1 = "37"
        End If
        If lblCounter1.Text = "38" Then
            CurrentFolder1 = "38"
        End If
        If lblCounter1.Text = "39" Then
            CurrentFolder1 = "39"
        End If
        If lblCounter1.Text = "40" Then
            CurrentFolder1 = "40"
        End If
        If lblCounter1.Text = "41" Then
            CurrentFolder1 = "41"
        End If
        If lblCounter1.Text = "42" Then
            CurrentFolder1 = "42"
        End If
        If lblCounter1.Text = "43" Then
            CurrentFolder1 = "43"
        End If
        If lblCounter1.Text = "44" Then
            CurrentFolder1 = "44"
        End If
        If lblCounter1.Text = "45" Then
            CurrentFolder1 = "45"
        End If
        If lblCounter1.Text = "46" Then
            CurrentFolder1 = "46"
        End If
        If lblCounter1.Text = "47" Then
            CurrentFolder1 = "47"
        End If
        If lblCounter1.Text = "48" Then
            CurrentFolder1 = "48"
        End If
        If lblCounter1.Text = "49" Then
            CurrentFolder1 = "49"
        End If
        If lblCounter1.Text = "50" Then
            CurrentFolder1 = "50"
        End If
        If lblCounter1.Text = "51" Then
            CurrentFolder1 = "51"
        End If
        If lblCounter1.Text = "52" Then
            CurrentFolder1 = "52"
        End If
        If lblCounter1.Text = "53" Then
            CurrentFolder1 = "53"
        End If
        If lblCounter1.Text = "54" Then
            CurrentFolder1 = "54"
        End If
        If lblCounter1.Text = "55" Then
            CurrentFolder1 = "55"
        End If
        If lblCounter1.Text = "56" Then
            CurrentFolder1 = "56"
        End If
        If lblCounter1.Text = "57" Then
            CurrentFolder1 = "57"
        End If
        If lblCounter1.Text = "58" Then
            CurrentFolder1 = "58"
        End If
        If lblCounter1.Text = "59" Then
            CurrentFolder1 = "59"
        End If
        If lblCounter1.Text = "60" Then
            CurrentFolder1 = "60"
        End If
        If lblCounter1.Text = "61" Then
            CurrentFolder1 = "61"
        End If
        If lblCounter1.Text = "62" Then
            CurrentFolder1 = "62"
        End If
        If lblCounter1.Text = "63" Then
            CurrentFolder1 = "63"
        End If
 
 
 
 
 
        'STOP THE THREAD PROCESS on 64
        If lblCounter1.Text = "64" Then
            GoTo DONE
 
 
        End If
 
 
 
        'Make sure it is a legit folder
        source1 = source1 & "\" & CurrentFolder1
        dest1 = dest1 & "\" & CurrentFolder1
 
 
        If Not (Directory.Exists(source1) AndAlso Directory.Exists(dest1)) Then
            MessageBox.Show("Directory Source or Destination Does Not Exist. Please Correct", "Directory Not Found")
            MsgBox("Source: " & source1 & vbCrLf & "Destination: " & dest1)
 
            Return
        End If
 
 
        ' Parameters to send to the BackgroundWorker Source & Destination directories
        Dim params1() As Object = {source1, dest1}
        ' Run the BackgroundWorker
 
        'Uncomment out this line if you want to see each folder prior to it copying
        'MsgBox("About to Copy Using:" & vbCrLf & vbCrLf & "Source: " & source & vbCrLf & "Destination: " & dest)
 
 
        BackgroundWorker1.RunWorkerAsync(params1)
DONE:
        '    MsgBox("FINISHED copying Group!")
 
    End Sub
 
 
 
    Private Sub LaunchBGWorker2()
        Me.Refresh()
 
 
 
        source2 = lblSource.Text
        dest2 = lblDest.Text
        'source = TextBox1.Text
        'dest = TextBox2.Text
 
 
        'If lblCounter2.Text = "0" Then
        '    currentfolder2 = "63"
        'End If
        If lblCounter4.Text = "0" Then
            CurrentFolder2 = "FF"
        End If
        If lblCounter2.Text = "1" Then
            CurrentFolder2 = "64"
        End If
        If lblCounter2.Text = "2" Then
            CurrentFolder2 = "65"
        End If
        If lblCounter2.Text = "3" Then
            CurrentFolder2 = "66"
        End If
        If lblCounter2.Text = "4" Then
            CurrentFolder2 = "67"
        End If
        If lblCounter2.Text = "5" Then
            CurrentFolder2 = "68"
        End If
        If lblCounter2.Text = "6" Then
            CurrentFolder2 = "69"
        End If
        If lblCounter2.Text = "7" Then
            CurrentFolder2 = "70"
        End If
        If lblCounter2.Text = "8" Then
            CurrentFolder2 = "71"
        End If
        If lblCounter2.Text = "9" Then
            CurrentFolder2 = "72"
        End If
        If lblCounter2.Text = "10" Then
            CurrentFolder2 = "73"
        End If
        If lblCounter2.Text = "11" Then
            CurrentFolder2 = "74"
        End If
        If lblCounter2.Text = "12" Then
            CurrentFolder2 = "75"
        End If
        If lblCounter2.Text = "13" Then
            CurrentFolder2 = "76"
        End If
        If lblCounter2.Text = "14" Then
            CurrentFolder2 = "77"
        End If
        If lblCounter2.Text = "15" Then
            CurrentFolder2 = "78"
        End If
        If lblCounter2.Text = "16" Then
            CurrentFolder2 = "79"
        End If
        If lblCounter2.Text = "17" Then
            CurrentFolder2 = "80"
        End If
        If lblCounter2.Text = "18" Then
            CurrentFolder2 = "81"
        End If
        If lblCounter2.Text = "19" Then
            CurrentFolder2 = "82"
        End If
        If lblCounter2.Text = "20" Then
            CurrentFolder2 = "83"
        End If
        If lblCounter2.Text = "21" Then
            CurrentFolder2 = "84"
        End If
        If lblCounter2.Text = "22" Then
            CurrentFolder2 = "85"
        End If
        If lblCounter2.Text = "23" Then
            CurrentFolder2 = "86"
        End If
        If lblCounter2.Text = "24" Then
            CurrentFolder2 = "87"
        End If
        If lblCounter2.Text = "25" Then
            CurrentFolder2 = "88"
        End If
        If lblCounter2.Text = "26" Then
            CurrentFolder2 = "89"
        End If
        If lblCounter2.Text = "27" Then
            CurrentFolder2 = "90"
        End If
        If lblCounter2.Text = "28" Then
            CurrentFolder2 = "91"
        End If
        If lblCounter2.Text = "29" Then
            CurrentFolder2 = "92"
        End If
        If lblCounter2.Text = "30" Then
            CurrentFolder2 = "93"
        End If
        If lblCounter2.Text = "31" Then
            CurrentFolder2 = "94"
        End If
        If lblCounter2.Text = "32" Then
            CurrentFolder2 = "95"
        End If
        If lblCounter2.Text = "33" Then
            CurrentFolder2 = "96"
        End If
        If lblCounter2.Text = "34" Then
            CurrentFolder2 = "97"
        End If
        If lblCounter2.Text = "35" Then
            CurrentFolder2 = "98"
        End If
        If lblCounter2.Text = "36" Then
            CurrentFolder2 = "99"
        End If
        If lblCounter2.Text = "37" Then
            CurrentFolder2 = "0A"
        End If
        If lblCounter2.Text = "38" Then
            CurrentFolder2 = "0B"
        End If
        If lblCounter2.Text = "39" Then
            CurrentFolder2 = "0C"
        End If
        If lblCounter2.Text = "40" Then
            CurrentFolder2 = "0D"
        End If
        If lblCounter2.Text = "41" Then
            CurrentFolder2 = "0E"
        End If
        If lblCounter2.Text = "42" Then
            CurrentFolder2 = "0F"
        End If
        If lblCounter2.Text = "43" Then
            CurrentFolder2 = "1A"
        End If
        If lblCounter2.Text = "44" Then
            CurrentFolder2 = "1B"
        End If
        If lblCounter2.Text = "45" Then
            CurrentFolder2 = "1C"
        End If
        If lblCounter2.Text = "46" Then
            CurrentFolder2 = "1D"
        End If
        If lblCounter2.Text = "47" Then
            CurrentFolder2 = "1E"
        End If
        If lblCounter2.Text = "48" Then
            CurrentFolder2 = "1F"
        End If
        If lblCounter2.Text = "49" Then
            CurrentFolder2 = "2A"
        End If
        If lblCounter2.Text = "50" Then
            CurrentFolder2 = "2B"
        End If
        If lblCounter2.Text = "51" Then
            CurrentFolder2 = "2C"
        End If
        If lblCounter2.Text = "52" Then
            CurrentFolder2 = "2D"
        End If
        If lblCounter2.Text = "53" Then
            CurrentFolder2 = "2E"
        End If
        If lblCounter2.Text = "54" Then
            CurrentFolder2 = "2F"
        End If
        If lblCounter2.Text = "55" Then
            CurrentFolder2 = "3A"
        End If
        If lblCounter2.Text = "56" Then
            CurrentFolder2 = "3B"
        End If
        If lblCounter2.Text = "57" Then
            CurrentFolder2 = "3C"
        End If
        If lblCounter2.Text = "58" Then
            CurrentFolder2 = "3D"
        End If
        If lblCounter2.Text = "59" Then
            CurrentFolder2 = "3E"
        End If
        If lblCounter2.Text = "60" Then
            CurrentFolder2 = "3F"
        End If
        If lblCounter2.Text = "61" Then
            CurrentFolder2 = "4A"
        End If
        If lblCounter2.Text = "62" Then
            CurrentFolder2 = "4B"
        End If
        If lblCounter2.Text = "63" Then
            CurrentFolder2 = "4C"
        End If
 
 
 
 
 
        'STOP THE THREAD PROCESS on 64
        If lblCounter2.Text = "64" Then
            GoTo DONE
 
 
        End If
 
 
 
        'Make sure it is a legit folder
        source2 = source2 & "\" & CurrentFolder2
        dest2 = dest2 & "\" & CurrentFolder2
 
 
        If Not (Directory.Exists(source2) AndAlso Directory.Exists(dest2)) Then
            MessageBox.Show("Directory Source or Destination Does Not Exist. Please Correct", "Directory Not Found")
            MsgBox("Source: " & source2 & vbCrLf & "Destination: " & dest2)
 
            Return
        End If
 
 
        ' Parameters to send to the BackgroundWorker Source & Destination directories
        Dim params2() As Object = {source2, dest2}
        ' Run the BackgroundWorker
 
        'Uncomment out this line if you want to see each folder prior to it copying
        'MsgBox("About to Copy Using:" & vbCrLf & vbCrLf & "Source: " & source & vbCrLf & "Destination: " & dest)
 
 
        BackgroundWorker2.RunWorkerAsync(params2)
DONE:
        '    MsgBox("FINISHED copying Group!")
 
    End Sub
 
 
 
    Private Sub LaunchBGWorker3()
        Me.Refresh()
 
        source3 = lblSource.Text
        dest3 = lblDest.Text
        'source = TextBox1.Text
        'dest = TextBox2.Text
 
 
        If lblCounter3.Text = "0" Then
            CurrentFolder3 = "4D"
        End If
        If lblCounter3.Text = "1" Then
            CurrentFolder3 = "4E"
        End If
        If lblCounter3.Text = "2" Then
            CurrentFolder3 = "4F"
        End If
        If lblCounter3.Text = "3" Then
            CurrentFolder3 = "5A"
        End If
        If lblCounter3.Text = "4" Then
            CurrentFolder3 = "5B"
        End If
        If lblCounter3.Text = "5" Then
            CurrentFolder3 = "5C"
        End If
        If lblCounter3.Text = "6" Then
            CurrentFolder3 = "5D"
        End If
        If lblCounter3.Text = "7" Then
            CurrentFolder3 = "5E"
        End If
        If lblCounter3.Text = "8" Then
            CurrentFolder3 = "5F"
        End If
        If lblCounter3.Text = "9" Then
            CurrentFolder3 = "6A"
        End If
        If lblCounter3.Text = "10" Then
            CurrentFolder3 = "6B"
        End If
        If lblCounter3.Text = "11" Then
            CurrentFolder3 = "6C"
        End If
        If lblCounter3.Text = "12" Then
            CurrentFolder3 = "6D"
        End If
        If lblCounter3.Text = "13" Then
            CurrentFolder3 = "6E"
        End If
        If lblCounter3.Text = "14" Then
            CurrentFolder3 = "6F"
        End If
        If lblCounter3.Text = "15" Then
            CurrentFolder3 = "7A"
        End If
        If lblCounter3.Text = "16" Then
            CurrentFolder3 = "7B"
        End If
        If lblCounter3.Text = "17" Then
            CurrentFolder3 = "7C"
        End If
        If lblCounter3.Text = "18" Then
            CurrentFolder3 = "7D"
        End If
        If lblCounter3.Text = "19" Then
            CurrentFolder3 = "7E"
        End If
        If lblCounter3.Text = "20" Then
            CurrentFolder3 = "7F"
        End If
        If lblCounter3.Text = "21" Then
            CurrentFolder3 = "8A"
        End If
        If lblCounter3.Text = "22" Then
            CurrentFolder3 = "8B"
        End If
        If lblCounter3.Text = "23" Then
            CurrentFolder3 = "8C"
        End If
        If lblCounter3.Text = "24" Then
            CurrentFolder3 = "8D"
        End If
        If lblCounter3.Text = "25" Then
            CurrentFolder3 = "8E"
        End If
        If lblCounter3.Text = "26" Then
            CurrentFolder3 = "8F"
        End If
        If lblCounter3.Text = "27" Then
            CurrentFolder3 = "9A"
        End If
        If lblCounter3.Text = "28" Then
            CurrentFolder3 = "9B"
        End If
        If lblCounter3.Text = "29" Then
            CurrentFolder3 = "9C"
        End If
        If lblCounter3.Text = "30" Then
            CurrentFolder3 = "9D"
        End If
        If lblCounter3.Text = "31" Then
            CurrentFolder3 = "9E"
        End If
        If lblCounter3.Text = "32" Then
            CurrentFolder3 = "9F"
        End If
        If lblCounter3.Text = "33" Then
            CurrentFolder3 = "A0"
        End If
        If lblCounter3.Text = "34" Then
            CurrentFolder3 = "A1"
        End If
        If lblCounter3.Text = "35" Then
            CurrentFolder3 = "A2"
        End If
        If lblCounter3.Text = "36" Then
            CurrentFolder3 = "A3"
        End If
        If lblCounter3.Text = "37" Then
            CurrentFolder3 = "A4"
        End If
        If lblCounter3.Text = "38" Then
            CurrentFolder3 = "A5"
        End If
        If lblCounter3.Text = "39" Then
            CurrentFolder3 = "A6"
        End If
        If lblCounter3.Text = "40" Then
            CurrentFolder3 = "A7"
        End If
        If lblCounter3.Text = "41" Then
            CurrentFolder3 = "A8"
        End If
        If lblCounter3.Text = "42" Then
            CurrentFolder3 = "A9"
        End If
        If lblCounter3.Text = "43" Then
            CurrentFolder3 = "B0"
        End If
        If lblCounter3.Text = "44" Then
            CurrentFolder3 = "B1"
        End If
        If lblCounter3.Text = "45" Then
            CurrentFolder3 = "B2"
        End If
        If lblCounter3.Text = "46" Then
            CurrentFolder3 = "B3"
        End If
        If lblCounter3.Text = "47" Then
            CurrentFolder3 = "B4"
        End If
        If lblCounter3.Text = "48" Then
            CurrentFolder3 = "B5"
        End If
        If lblCounter3.Text = "49" Then
            CurrentFolder3 = "B6"
        End If
        If lblCounter3.Text = "50" Then
            CurrentFolder3 = "B7"
        End If
        If lblCounter3.Text = "51" Then
            CurrentFolder3 = "B8"
        End If
        If lblCounter3.Text = "52" Then
            CurrentFolder3 = "B9"
        End If
        If lblCounter3.Text = "53" Then
            CurrentFolder3 = "C0"
        End If
        If lblCounter3.Text = "54" Then
            CurrentFolder3 = "C1"
        End If
        If lblCounter3.Text = "55" Then
            CurrentFolder3 = "C2"
        End If
        If lblCounter3.Text = "56" Then
            CurrentFolder3 = "C3"
        End If
        If lblCounter3.Text = "57" Then
            CurrentFolder3 = "C4"
        End If
        If lblCounter3.Text = "58" Then
            CurrentFolder3 = "C5"
        End If
        If lblCounter3.Text = "59" Then
            CurrentFolder3 = "C6"
        End If
        If lblCounter3.Text = "60" Then
            CurrentFolder3 = "C7"
        End If
        If lblCounter3.Text = "61" Then
            CurrentFolder3 = "C8"
        End If
        If lblCounter3.Text = "62" Then
            CurrentFolder3 = "C9"
        End If
        If lblCounter3.Text = "63" Then
            CurrentFolder3 = "D0"
        End If
 
 
 
 
 
        'STOP THE THREAD PROCESS on 64
        If lblCounter3.Text = "64" Then
            GoTo DONE
 
 
        End If
 
 
 
        'Make sure it is a legit folder
        source3 = source3 & "\" & CurrentFolder3
        dest3 = dest3 & "\" & CurrentFolder3
 
 
        If Not (Directory.Exists(source3) AndAlso Directory.Exists(dest3)) Then
            MessageBox.Show("Directory Source or Destination Does Not Exist. Please Correct", "Directory Not Found")
            MsgBox("Source: " & source3 & vbCrLf & "Destination: " & dest3)
 
            Return
        End If
 
 
        ' Parameters to send to the BackgroundWorker Source & Destination directories
        Dim params3() As Object = {source3, dest3}
        ' Run the BackgroundWorker
 
        'Uncomment out this line if you want to see each folder prior to it copying
        'MsgBox("About to Copy Using:" & vbCrLf & vbCrLf & "Source: " & source & vbCrLf & "Destination: " & dest)
 
 
        BackgroundWorker3.RunWorkerAsync(params3)
DONE:
        '    MsgBox("FINISHED copying Group!")
 
    End Sub
 
 
 
    Private Sub LaunchBGWorker4()
        Me.Refresh()
 
        source4 = lblSource.Text
        dest4 = lblDest.Text
        'source = TextBox1.Text
        'dest = TextBox2.Text
 
 
        If lblCounter4.Text = "0" Then
            CurrentFolder4 = "D1"
        End If
        If lblCounter4.Text = "1" Then
            CurrentFolder4 = "D2"
        End If
        If lblCounter4.Text = "2" Then
            CurrentFolder4 = "D3"
        End If
        If lblCounter4.Text = "3" Then
            CurrentFolder4 = "D4"
        End If
        If lblCounter4.Text = "4" Then
            CurrentFolder4 = "D5"
        End If
        If lblCounter4.Text = "5" Then
            CurrentFolder4 = "D6"
        End If
        If lblCounter4.Text = "6" Then
            CurrentFolder4 = "D7"
        End If
        If lblCounter4.Text = "7" Then
            CurrentFolder4 = "D8"
        End If
        If lblCounter4.Text = "8" Then
            CurrentFolder4 = "D9"
        End If
        If lblCounter4.Text = "9" Then
            CurrentFolder4 = "E0"
        End If
        If lblCounter4.Text = "10" Then
            CurrentFolder4 = "E1"
        End If
        If lblCounter4.Text = "11" Then
            CurrentFolder4 = "E2"
        End If
        If lblCounter4.Text = "12" Then
            CurrentFolder4 = "E3"
        End If
        If lblCounter4.Text = "13" Then
            CurrentFolder4 = "E4"
        End If
        If lblCounter4.Text = "14" Then
            CurrentFolder4 = "E5"
        End If
        If lblCounter4.Text = "15" Then
            CurrentFolder4 = "E6"
        End If
        If lblCounter4.Text = "16" Then
            CurrentFolder4 = "E7"
        End If
        If lblCounter4.Text = "17" Then
            CurrentFolder4 = "E8"
        End If
        If lblCounter4.Text = "18" Then
            CurrentFolder4 = "E9"
        End If
        If lblCounter4.Text = "19" Then
            CurrentFolder4 = "F0"
        End If
        If lblCounter4.Text = "20" Then
            CurrentFolder4 = "F1"
        End If
        If lblCounter4.Text = "21" Then
            CurrentFolder4 = "F2"
        End If
        If lblCounter4.Text = "22" Then
            CurrentFolder4 = "F3"
        End If
        If lblCounter4.Text = "23" Then
            CurrentFolder4 = "F4"
        End If
        If lblCounter4.Text = "24" Then
            CurrentFolder4 = "F5"
        End If
        If lblCounter4.Text = "25" Then
            CurrentFolder4 = "F6"
        End If
        If lblCounter4.Text = "26" Then
            CurrentFolder4 = "F7"
        End If
        If lblCounter4.Text = "27" Then
            CurrentFolder4 = "F8"
        End If
        If lblCounter4.Text = "28" Then
            CurrentFolder4 = "F9"
        End If
        If lblCounter4.Text = "29" Then
            CurrentFolder4 = "AA"
        End If
        If lblCounter4.Text = "30" Then
            CurrentFolder4 = "AB"
        End If
        If lblCounter4.Text = "31" Then
            CurrentFolder4 = "AC"
        End If
        If lblCounter4.Text = "32" Then
            CurrentFolder4 = "AD"
        End If
        If lblCounter4.Text = "33" Then
            CurrentFolder4 = "AE"
        End If
        If lblCounter4.Text = "34" Then
            CurrentFolder4 = "AF"
        End If
        If lblCounter4.Text = "35" Then
            CurrentFolder4 = "BA"
        End If
        If lblCounter4.Text = "36" Then
            CurrentFolder4 = "BB"
        End If
        If lblCounter4.Text = "37" Then
            CurrentFolder4 = "BC"
        End If
        If lblCounter4.Text = "38" Then
            CurrentFolder4 = "BD"
        End If
        If lblCounter4.Text = "39" Then
            CurrentFolder4 = "BE"
        End If
        If lblCounter4.Text = "40" Then
            CurrentFolder4 = "BF"
        End If
        If lblCounter4.Text = "41" Then
            CurrentFolder4 = "CA"
        End If
        If lblCounter4.Text = "42" Then
            CurrentFolder4 = "CB"
        End If
        If lblCounter4.Text = "43" Then
            CurrentFolder4 = "CC"
        End If
        If lblCounter4.Text = "44" Then
            CurrentFolder4 = "CD"
        End If
        If lblCounter4.Text = "45" Then
            CurrentFolder4 = "CE"
        End If
        If lblCounter4.Text = "46" Then
            CurrentFolder4 = "CF"
        End If
        If lblCounter4.Text = "47" Then
            CurrentFolder4 = "DA"
        End If
        If lblCounter4.Text = "48" Then
            CurrentFolder4 = "DB"
        End If
        If lblCounter4.Text = "49" Then
            CurrentFolder4 = "DC"
        End If
        If lblCounter4.Text = "50" Then
            CurrentFolder4 = "DD"
        End If
        If lblCounter4.Text = "51" Then
            CurrentFolder4 = "DE"
        End If
        If lblCounter4.Text = "52" Then
            CurrentFolder4 = "DF"
        End If
        If lblCounter4.Text = "53" Then
            CurrentFolder4 = "EA"
        End If
        If lblCounter4.Text = "54" Then
            CurrentFolder4 = "EB"
        End If
        If lblCounter4.Text = "55" Then
            CurrentFolder4 = "EC"
        End If
        If lblCounter4.Text = "56" Then
            CurrentFolder4 = "ED"
        End If
        If lblCounter4.Text = "57" Then
            CurrentFolder4 = "EE"
        End If
        If lblCounter4.Text = "58" Then
            CurrentFolder4 = "EF"
        End If
        If lblCounter4.Text = "59" Then
            CurrentFolder4 = "FA"
        End If
        If lblCounter4.Text = "60" Then
            CurrentFolder4 = "FB"
        End If
        If lblCounter4.Text = "61" Then
            CurrentFolder4 = "FC"
        End If
        If lblCounter4.Text = "62" Then
            CurrentFolder4 = "FD"
        End If
        If lblCounter4.Text = "63" Then
            CurrentFolder4 = "FE"
        End If
        'If lblCounter4.Text = "64" Then
        '    currentfolder4 = "FF"
        'End If
 
 
 
 
 
        'STOP THE THREAD PROCESS on 64
        If lblCounter4.Text = "64" Then
            GoTo DONE
 
 
        End If
 
 
 
        'Make sure it is a legit folder
        source4 = source4 & "\" & CurrentFolder4
        dest4 = dest4 & "\" & CurrentFolder4
 
 
        If Not (Directory.Exists(source4) AndAlso Directory.Exists(dest4)) Then
            MessageBox.Show("Directory Source or Destination Does Not Exist. Please Correct", "Directory Not Found")
            MsgBox("Source: " & source4 & vbCrLf & "Destination: " & dest4)
 
            Return
        End If
 
 
        ' Parameters to send to the BackgroundWorker Source & Destination directories
        Dim params4() As Object = {source4, dest4}
        ' Run the BackgroundWorker
 
        'Uncomment out this line if you want to see each folder prior to it copying
        'MsgBox("About to Copy Using:" & vbCrLf & vbCrLf & "Source: " & source & vbCrLf & "Destination: " & dest)
 
 
        BackgroundWorker4.RunWorkerAsync(params4)
DONE:
        '    MsgBox("FINISHED copying Group!")
 
    End Sub
 
 
    Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As System.Object, _
            ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
 
        ' If the Maximum number of files is in the argument set it 
        If e.UserState IsNot Nothing Then ProgressBar1.Maximum = CType(e.UserState, Integer)
        ' Update the ProgressBar control
        ProgressBar1.Increment(e.ProgressPercentage)
        ProgressBar1.Refresh()
 
 
 
 
 
 
    End Sub
 
    Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, _
            ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
 
        ' Set the ProgressBar to Max is it is not there already
        ProgressBar1.Value = ProgressBar1.Maximum
        lblCounter1.Text = lblCounter1.Text + 1
        ProgressBar1.Value = 0
        LaunchBGWorker1()
 
 
 
 
 
    End Sub
    Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, _
 ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
   
 
        ' Get the parameters sent to the BackgroundWorker
        Dim sourceDirPath As String = e.Argument(0)
        Dim destinationDirPath As String = e.Argument(1)
        ' Get the file information from the source directory
        Dim sourceDirectory As DirectoryInfo = New DirectoryInfo(sourceDirPath)
        Dim sourceFiles() As FileInfo = sourceDirectory.GetFiles()
        ' Get the number of files to copy to the destination directory
        Dim Maximum = sourceFiles.Length.ToString()
        ' Set up progress bar with initial values 
        BackgroundWorker1.ReportProgress(0, Maximum)
 
        For Each fi As FileInfo In sourceFiles
            ' Check to see if Destination file exist 
            If File.Exists(destinationDirPath & "\" & fi.Name) Then
                ' Destination file exist. Check to see if source is newer 
                If fi.LastWriteTime > File.GetLastWriteTime(destinationDirPath & "\" & fi.Name) Then
                    'Source is newer so overwrite the destination file
                    Try
                        ' The last parameter is to overwite an existing file in the destination
                        My.Computer.FileSystem.CopyFile(fi.FullName, destinationDirPath & "\" & fi.Name, True)
                        BackgroundWorker1.ReportProgress(1)
                        lblFileName1.Text = fi.FullName
                        lblCurrentFolder1.Text = CurrentFolder1
                    Catch ex As Exception
                        ' File may be in use log it to a file so that you can try later
                    End Try
                End If
            Else
                ' Destination file does not exist so just write it
                Try
                    ' The last parameter is to overwite an existing file in the destination
                    My.Computer.FileSystem.CopyFile(fi.FullName, destinationDirPath & "\" & fi.Name, True)
                    BackgroundWorker1.ReportProgress(1)
                Catch ex As Exception
                    ' File may be in use log it to a file so that you can try later
                End Try
            End If
        Next
 
    End Sub
 
 
 
    Private Sub BackgroundWorker2_ProgressChanged(ByVal sender As System.Object, _
            ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker2.ProgressChanged
 
        ' If the Maximum number of files is in the argument set it 
        If e.UserState IsNot Nothing Then ProgressBar2.Maximum = CType(e.UserState, Integer)
        ' Update the ProgressBar control
        ProgressBar2.Increment(e.ProgressPercentage)
        ProgressBar2.Refresh()
 
 
 
 
 
 
    End Sub
 
    Private Sub BackgroundWorker2_RunWorkerCompleted(ByVal sender As Object, _
            ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker2.RunWorkerCompleted
 
        ' Set the ProgressBar to Max is it is not there already
        ProgressBar2.Value = ProgressBar2.Maximum
        lblCounter2.Text = lblCounter2.Text + 1
        ProgressBar2.Value = 0
        LaunchBGWorker2()
 
 
 
 
 
    End Sub
    Private Sub BackgroundWorker2_DoWork(ByVal sender As System.Object, _
 ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker2.DoWork
 
 
        ' Get the parameters sent to the BackgroundWorker
        Dim sourceDirPath As String = e.Argument(0)
        Dim destinationDirPath As String = e.Argument(1)
        ' Get the file information from the source directory
        Dim sourceDirectory As DirectoryInfo = New DirectoryInfo(sourceDirPath)
        Dim sourceFiles() As FileInfo = sourceDirectory.GetFiles()
        ' Get the number of files to copy to the destination directory
        Dim Maximum = sourceFiles.Length.ToString()
        ' Set up progress bar with initial values 
        BackgroundWorker2.ReportProgress(0, Maximum)
 
        For Each fi As FileInfo In sourceFiles
            ' Check to see if Destination file exist 
            If File.Exists(destinationDirPath & "\" & fi.Name) Then
                ' Destination file exist. Check to see if source is newer 
                If fi.LastWriteTime > File.GetLastWriteTime(destinationDirPath & "\" & fi.Name) Then
                    'Source is newer so overwrite the destination file
                    Try
                        ' The last parameter is to overwite an existing file in the destination
                        My.Computer.FileSystem.CopyFile(fi.FullName, destinationDirPath & "\" & fi.Name, True)
                        BackgroundWorker2.ReportProgress(1)
                        lblFileName2.Text = fi.FullName
                        lblCurrentFolder2.Text = CurrentFolder2
                    Catch ex As Exception
                        ' File may be in use log it to a file so that you can try later
                    End Try
                End If
            Else
                ' Destination file does not exist so just write it
                Try
                    ' The last parameter is to overwite an existing file in the destination
                    My.Computer.FileSystem.CopyFile(fi.FullName, destinationDirPath & "\" & fi.Name, True)
                    BackgroundWorker2.ReportProgress(1)
                Catch ex As Exception
                    ' File may be in use log it to a file so that you can try later
                End Try
            End If
        Next
 
    End Sub
 
 
 
 
    Private Sub backgroundworker3_ProgressChanged(ByVal sender As System.Object, _
            ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker3.ProgressChanged
 
        ' If the Maximum number of files is in the argument set it 
        If e.UserState IsNot Nothing Then ProgressBar3.Maximum = CType(e.UserState, Integer)
        ' Update the ProgressBar control
        ProgressBar3.Increment(e.ProgressPercentage)
        ProgressBar3.Refresh()
 
 
 
 
 
 
    End Sub
 
    Private Sub backgroundworker3_RunWorkerCompleted(ByVal sender As Object, _
            ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker3.RunWorkerCompleted
 
        ' Set the ProgressBar to Max is it is not there already
        ProgressBar3.Value = ProgressBar3.Maximum
        lblCounter3.Text = lblCounter3.Text + 1
        ProgressBar3.Value = 0
        LaunchBGWorker3()
 
 
 
 
 
    End Sub
    Private Sub backgroundworker3_DoWork(ByVal sender As System.Object, _
 ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker3.DoWork
 
 
        ' Get the parameters sent to the BackgroundWorker
        Dim sourceDirPath As String = e.Argument(0)
        Dim destinationDirPath As String = e.Argument(1)
        ' Get the file information from the source directory
        Dim sourceDirectory As DirectoryInfo = New DirectoryInfo(sourceDirPath)
        Dim sourceFiles() As FileInfo = sourceDirectory.GetFiles()
        ' Get the number of files to copy to the destination directory
        Dim Maximum = sourceFiles.Length.ToString()
        ' Set up progress bar with initial values 
        BackgroundWorker3.ReportProgress(0, Maximum)
 
        For Each fi As FileInfo In sourceFiles
            ' Check to see if Destination file exist 
            If File.Exists(destinationDirPath & "\" & fi.Name) Then
                ' Destination file exist. Check to see if source is newer 
                If fi.LastWriteTime > File.GetLastWriteTime(destinationDirPath & "\" & fi.Name) Then
                    'Source is newer so overwrite the destination file
                    Try
                        ' The last parameter is to overwite an existing file in the destination
                        My.Computer.FileSystem.CopyFile(fi.FullName, destinationDirPath & "\" & fi.Name, True)
                        BackgroundWorker3.ReportProgress(1)
                        lblFileName3.Text = fi.FullName
                        lblCurrentFolder3.Text = CurrentFolder3
                    Catch ex As Exception
                        ' File may be in use log it to a file so that you can try later
                    End Try
                End If
            Else
                ' Destination file does not exist so just write it
                Try
                    ' The last parameter is to overwite an existing file in the destination
                    My.Computer.FileSystem.CopyFile(fi.FullName, destinationDirPath & "\" & fi.Name, True)
                    BackgroundWorker3.ReportProgress(1)
                Catch ex As Exception
                    ' File may be in use log it to a file so that you can try later
                End Try
            End If
        Next
 
    End Sub
 
 
 
 
    Private Sub BackgroundWorker4_ProgressChanged(ByVal sender As System.Object, _
            ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
 
        ' If the Maximum number of files is in the argument set it 
        If e.UserState IsNot Nothing Then ProgressBar4.Maximum = CType(e.UserState, Integer)
        ' Update the ProgressBar control
        ProgressBar4.Increment(e.ProgressPercentage)
        ProgressBar4.Refresh()
 
 
 
 
 
 
    End Sub
 
    Private Sub BackgroundWorker4_RunWorkerCompleted(ByVal sender As Object, _
            ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
 
        ' Set the ProgressBar to Max is it is not there already
        ProgressBar4.Value = ProgressBar4.Maximum
        lblCounter4.Text = lblCounter4.Text + 1
        ProgressBar4.Value = 0
        LaunchBGWorker4()
 
 
 
 
 
    End Sub
    Private Sub BackgroundWorker4_DoWork(ByVal sender As System.Object, _
 ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
 
 
        ' Get the parameters sent to the BackgroundWorker
        Dim sourceDirPath As String = e.Argument(0)
        Dim destinationDirPath As String = e.Argument(1)
        ' Get the file information from the source directory
        Dim sourceDirectory As DirectoryInfo = New DirectoryInfo(sourceDirPath)
        Dim sourceFiles() As FileInfo = sourceDirectory.GetFiles()
        ' Get the number of files to copy to the destination directory
        Dim Maximum = sourceFiles.Length.ToString()
        ' Set up progress bar with initial values 
        BackgroundWorker4.ReportProgress(0, Maximum)
 
        For Each fi As FileInfo In sourceFiles
            ' Check to see if Destination file exist 
            If File.Exists(destinationDirPath & "\" & fi.Name) Then
                ' Destination file exist. Check to see if source is newer 
                If fi.LastWriteTime > File.GetLastWriteTime(destinationDirPath & "\" & fi.Name) Then
                    'Source is newer so overwrite the destination file
                    Try
                        ' The last parameter is to overwite an existing file in the destination
                        My.Computer.FileSystem.CopyFile(fi.FullName, destinationDirPath & "\" & fi.Name, True)
                        BackgroundWorker4.ReportProgress(1)
                        lblFileName4.Text = fi.FullName
                        lblCurrentFolder4.Text = CurrentFolder4
                    Catch ex As Exception
                        ' File may be in use log it to a file so that you can try later
                    End Try
                End If
            Else
                ' Destination file does not exist so just write it
                Try
                    ' The last parameter is to overwite an existing file in the destination
                    My.Computer.FileSystem.CopyFile(fi.FullName, destinationDirPath & "\" & fi.Name, True)
                    BackgroundWorker4.ReportProgress(1)
                Catch ex As Exception
                    ' File may be in use log it to a file so that you can try later
                End Try
            End If
        Next
 
    End Sub
 
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lblSource.Text = frmMain.CallXML("ServerPhotoDirXML")
        lblDest.Text = frmMain.CallXML("clientPhotoDirXML")
       
 
    End Sub
 
 
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim total As Integer
        Dim group1 As Integer
        Dim group2 As Integer
        Dim group3 As Integer
        Dim group4 As Integer
 
        group1 = lblCounter1.Text
        group2 = lblCounter2.Text
        group3 = lblCounter3.Text
        group4 = lblCounter4.Text
 
 
        total = group1 + group2 + group3 + group4
 
        lblTotalCount.Text = total
        lblTotalCount.Refresh()
 
        If total = 256 Then
            MsgBox("Copy of all 256 folders has completed!")
            Timer1.Enabled = False
            lblPleaseWait.Visible = False
 
 
        End If
 
 
 
    End Sub
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Close()
 
    End Sub
End Class

Open in new window

Image1.jpg
When I used the above code that I submitted -
a few things I noticed:

The progress bars are not accurate at all - the barely move...
its like the max = total number of files -
but it only increments 1 - when it copies a file...
so when it skips all the rest of the files it does not increment


also the label that tells what is copying - only tells you the file it is copying - not the files it is skipping..
so it can just sit there for a along time you think it is doing nothing - but it really is scanning and comparing..
kinda' like it does w/ the label i made..

i know i should have made this into a more efficient code - but I am struggling here as it is - I am a beginner...
any suggestions or help - gladly accepted.

This form does work though.. from what I have tested so far.
To your statement, "I am not too familiar with creating a list array.", See the Snippet 1 code below.

To your statement, "then i have to:"

do for each (folder)
     Dim params() As Object = {array items}
        ' Run the BackgroundWorker
        BackgroundWorker1.RunWorkerAsync(params)
loop

To enumerate over the List of folders see the snippet 1, For Each loop.

You can not use BackgroundWorker1 to create multiple BackgroundWorker's, you must wait till BackgroundWorker1 is done and then start the next one or create 1 BackgroundWorker object for each thread you want to start at the same time.

To your statement, "I got it to work - but I used 64 If then statements and a counter and assigned a number to each folder", The use of the 64 If statements is  not very efficient the following code snippet can replace all the If's.

        Dim CurrentFolder1 As String
        If lblCounter1.Text.Trim().Length = 1 Then
            CurrentFolder1 = "0" & lblCounter1.Text.Trim()
        Else
            CurrentFolder1 = lblCounter1.Text.Trim()
        End If




Snippet 1
 
Imports System.Collections
 
Public Class Form1
 
    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click
 
        ' Lets say you have these values in the strings
        Dim source1 As String = TextBox1.Text
        Dim dest1 As String = TextBox5.Text
        Dim source2 As String = TextBox2.Text
        Dim dest2 As String = TextBox6.Text
        Dim source3 As String = TextBox3.Text
        Dim dest3 As String = TextBox7.Text
        Dim source4 As String = TextBox4.Text
        Dim dest4 As String = TextBox8.Text
 
        ' Creating a List of String
        Dim listOfSource As List(Of String) = New List(Of String)()
        listOfSource.Add(source1)
        listOfSource.Add(source2)
        listOfSource.Add(source3)
        listOfSource.Add(source4)
        Dim listOfDestination As List(Of String) = New List(Of String)()
        listOfDestination.Add(dest1)
        listOfDestination.Add(dest2)
        listOfDestination.Add(dest3)
        listOfDestination.Add(dest4)
 
        ' Enumerate over the list to get its value
        Dim output As String = String.Empty
        For Each folder As String In listOfSource
            output &= folder & Environment.NewLine
        Next
 
        ' Display all the folder names
        MessageBox.Show(output)
 
        ' You can also access the list with an index like this
        MessageBox.Show(listOfDestination(1))
 
 
    End Sub
End Class

Open in new window

To your statement, "When I used the above code that I submitted - a few things I noticed:"

You need to use a different BackgroundWorker for each group.
Wow Thanks.!
Also to your response: ID:22808411
"
 Dim CurrentFolder1 As String
       If lblCounter1.Text.Trim().Length = 1 Then
           CurrentFolder1 = "0" & lblCounter1.Text.Trim()
       Else
           CurrentFolder1 = lblCounter1.Text.Trim()
       End If
"

Won't this only work if the folders are all numbered?

Note: in my post: ID:22808089
CODE SNIP: Line 777 - 970
The folders are HEX values not just numbered
only the first group (group01)
has folders that are all numbered 1- 64

So doesnt this If - then trim the label only work if the folders are all the same name as the counter increment?


in your comment:ID:22808424
To your statement, "When I used the above code that I submitted - a few things I noticed:"

You need to use a different BackgroundWorker for each group.

If you note the Snip of code:ID:22808089
LINES:
516: BackgroundWorker2
760: BackgroundWorker3
1007: BackgroundWorker4

I used 4 BgWorkers -
If you look at my image .jpg of the form
the top 3 groups (progress bars, counters, and labels)
update fine while it runs -
but the last group group4
which is associated bgworker4
did not change..

also all the progressbars do not seem to load more than 3 notches before they reset..
"The progress bars are not accurate at all - the barely move...
its like the max = total number of files -
but it only increments 1 - when it copies a file...
so when it skips all the rest of the files it does not increment"

Any suggestions?
 
I really appreciate all your time!


-Idea - Just trying to recap what I am trying to do - maybe I was kinda vague -
I know there is a very effecient way of doing this!

Please tell me if you think this will work.
Basically I have 4 groups of folders
each group has 64 folders
each of the 4 groups is its own Backgroundworker
-ultimately each background worker is responsible for copying 64 folders

the folder names are hard coded into the application -
the only thing that is variable is the source and dest
(ie c:\folder01 or s:\mydir\folder01 or s:\folder01 or c:\temp\folder01)
The source and dest a variable all the way upto the last subfolder name -

'this example 4E is a folder to copy
folder01 = "4E"
Source = Source & "\" & folder01
dest = dest & "\" & folder01


so no matter what the source and the dest are the folder names will never change
and it will always copy to the same folder name as source and dest.

So could I build the list of arrays with the 256 folders ( 4 groups of 64)
Then just have it run the group?
like go through each one by one?

Array01 example:
4E = index 0
4F = index 1
5A = index 2
5B = index 3
5C = index 4
5D = index 5
5E = index 6
5F = index 7
... for a total of 64 indexed items in the group
...for a total of 4 groups
... for a total of 256 folders (each folder is 2 characters)

so then I have the backgroundworker1 resposnsible for
running though groupArray01
for each: folder
check the files in the source and dest
copy all the newer or non existing ones over
then move onto the next folder in the array
and then tell me when the group has cycled though all the way.

Also: while it is running though the files - each group has a label that is updated on the main form:
this label will reflect the name of the file currently being checked or copied
and the progressbar will reflect the total number of files in the folder,
and the index of the file that it is on while copying or scanning to check the date written

And 4 counters that will show how many folders have completed copying / scanning for each group

and a total counter that adds the 4 group counters together

Sorry if this is redundant -
You have hooked me up so much already - if you have the time I would love a response - if not.. I appreciate everything you have already done - I have learned a LOT on this one.

To your question on post 22810402, "Won't this only work if the folders are all numbered?" Yes, as I was commenting on lines 40 - 231. If you can find a pattern in the sequence as in lines 40 - 231 then that would be a better solution. You may find a pattern in lines 777 - 970. You can use a line of code like this to get the numeric value of a hex value, &HD1 where the hex value of D1 is 209, So something like this is valid:

Dim x As Integer = 2
Dim value As Integer = &HD1 * x

Value now holds the numeric value of 418.
-------------------------------------------------------------------------------
To the questions on post 22810420, "I used 4 BgWorkers", I missed that, sorry.

To the question, "The progress bars are not accurate at all - the barely move...", The following code checks to see if the file to be copied is newer and if so copies it and updates the progress bar.

If fi.LastWriteTime > File.GetLastWriteTime(destinationDirPath & "\" & fi.Name) Then
    'Source is newer so overwrite the destination file
    Try
        ' The last parameter is to overwite an existing file in the destination
        My.Computer.FileSystem.CopyFile(fi.FullName, destinationDirPath & "\" & fi.Name, True)
        BackgroundWorker1.ReportProgress(1)
        lblFileName1.Text = fi.FullName
        lblCurrentFolder1.Text = CurrentFolder1
    Catch ex As Exception
            ' File may be in use log it to a file so that you can try later
    End Try
End If

But if the file is not newer then no copy and no update to the progress bar. The code I posted is a snippet of code and not a complete solution you need to go through the code and make it meet your needs. There needs to be an Else part to the If statement to reduce the max number of file Maximum to reflect the new total files to copy by reducing Maximum by 1 each time this happens.
What you want to do in post 22810469 will work. I have one suggestion and that is not to code the directories into the application because if one directory is add, or deleted your program will need to be modified and recompiled. Here is a way to dynamically get the directories.

     ' A class level variable to hold the list of directories. One list for each group
     Private sDir As New List(Of String)

    Private Sub Button3_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button3.Click

        ' The parent directory that holds all the directories to be processed can be a TextBox
        ' on the form or loaded from a configuration file.
        Dim parentDir As String = "C:\Temp"
        ' Get the list of all directories in the parent folder and store in list
        sDir.AddRange(Directory.GetDirectories(parentDir))

        ' When you want to enumerate the list use a For Each loop like this
        For Each dir As String In sDir
            ' dir is one of the directories in sDir being a full path with folder name
            Console.WriteLine(dir)
        Next

    End Sub

You will need the following namespaces for the above code to work.

Imports System.Collections.Generic
Imports System.IO
Wow - thank you!
Again - you have answered like 50 questions of mine here.
So I really appreciate it.
Everything worked.
The only thing that I had small issue with was I am using .Net 2.0
so I had to modify
" Dim Maximum = sourceFiles.Length.ToString()"
the .length part is for .Net 2.0
I guess? It threw and error and said it was not a supported name space for the array when I used the code you initially gave me - but I had forgot to mention I was using 2.0 on the App...

Thank you again!
I went by what was posted in the tag of the question, "VB.net Visual Basic 2008"

Not a problem, glad I was able to help.  ;=)
Yeah I am using VB.Net Visual Basic 2008 - but the system that the app runs on - only has 2.0 .NET framework.
I just changed the compile option in VB.net 2008 to 2.0 assembly.
Thanks!