Updated code from your other thread .
1 Button, 1 ProgressBar
Imports System.IO
Public Class Form1
Private sTemp1, sTemp2 As String '// TEMP.Strings, used as needed.
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim fbd As New FolderBrowserDialog : sTemp1 = "" : sTemp2 = ""
With fbd
.Description = "Select a folder to copy the content FROM..." '// Source.Folder
If .ShowDialog = Windows.Forms.DialogResult.OK Then sTemp1 = .SelectedPath
.Description = "Select a folder to copy the content TO..." '// Destination.Folder
If .ShowDialog = Windows.Forms.DialogResult.OK Then sTemp2 = .SelectedPath
If Not sTemp1 = "" OrElse Not sTemp2 = "" Then copyDirectory(sTemp1, sTemp2, , ProgressBar1)
End With
End Sub
Private Sub copyDirectory(ByVal selCoolSourcePath As String, ByVal selDestinationPath As String, Optional selCoolFileExtension As String = "*.*", Optional selCoolProgressBar As ProgressBar = Nothing)
sTemp1 = ""
With selCoolProgressBar
If Not selCoolProgressBar Is Nothing Then '// if ProgressBar sent, set .Value and .Maximum.
.Value = 0
.Maximum = Directory.GetFiles(selCoolSourcePath, selCoolFileExtension, IO.SearchOption.AllDirectories).Length
End If
If Not Directory.Exists(selDestinationPath) Then Directory.CreateDirectory(selDestinationPath) '// create Folder if needed.
For Each myCoolFile As String In My.Computer.FileSystem.GetFiles _
(selCoolSourcePath, FileIO.SearchOption.SearchAllSubDirectories, selCoolFileExtension) '// loop thru Source.Files.
sTemp1 = selDestinationPath & "\" & Path.GetFileName(myCoolFile) '// set .DestinationPath w/only the filename+extension.
If Not File.Exists(sTemp1) Then '// if .File Not.Exist, procced, Else it will error "for.now".
File.Copy(myCoolFile, sTemp1) '// copy File.over.
Else
' MsgBox("File.Exists in Destination.Folder, cannot copy." & vbNewLine & sTemp1, MsgBoxStyle.Information)
End If
If Not selCoolProgressBar Is Nothing Then .Value += 1 '// +=1 .Value, if ProgressBar sent.
Next
End With
MsgBox(".done.", MsgBoxStyle.Information)
End Sub
End Class .line:16. Private Sub copyDirectory(...) , has an Optional file.extension. It is currently set to get all files ("*.*") , though it can be set to only get certain file .extension types.
If Not sTemp1 = "" OrElse Not sTemp2 = "" Then copyDirectory(sTemp1, sTemp2, "*.png", ProgressBar1) Hope this helps. :)